Skip to content

Instantly share code, notes, and snippets.

View alexmustin's full-sized avatar

Alex Mustin alexmustin

View GitHub Profile
@alexmustin
alexmustin / style.css
Last active August 12, 2020 01:53
CSS - Responsive Body and Header font sizes
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: calc(.35vw + 1rem);
line-height: 1.8;
}
h1 {
font-size: calc(2.0vw + 1rem);
}
@alexmustin
alexmustin / block-style-variations.js
Created August 5, 2020 19:08
WP - Add block style variations
jQuery(document).ready(function($) {
// Add 'Semibold' style to Paragraph blocks
wp.blocks.registerBlockStyle("core/paragraph", {
name: "semibold",
label: "Semibold"
});
// Add 'Black' style to Paragraph blocks
wp.blocks.registerBlockStyle("core/paragraph", {
@alexmustin
alexmustin / header.php
Last active August 3, 2020 23:02
Understrap - Off-canvas Mobile Menu
<?php
// ...
<!-- // HAMBURGER MENU TOGGLE // -->
<button class="navbar-toggler" type="button" data-toggle="modal" data-target="#menuModal" aria-controls="#menuModal" aria-expanded="false" aria-label="<?php esc_attr_e( 'Toggle navigation', 'understrap' ); ?>">
<i class="fa fa-bars menu_burger" aria-hidden="true"></i>
</button>
<!-- // DESKTOP MENU // -->
<?php wp_nav_menu(
@alexmustin
alexmustin / functions.php
Created July 17, 2020 21:35 — forked from sirchrispy/functions.php
WP: Allow shortcodes everywhere
//* Shortcode optimization
add_filter( 'the_content', 'do_shortcode' ); // Allow shortcodes inside of shortcodes
add_filter( 'comment_text', 'do_shortcode' ); // Allow shortcodes in comments
add_filter( 'comment_text', 'shortcode_unautop' ); // Prevent comment shortcodes from wrapping in <p>...</p> tags
add_filter( 'the_excerpt', 'do_shortcode' ); // Allow shortcodes in excerpts
add_filter( 'the_excerpt', 'shortcode_unautop' ); // Prevent excerpt shortcodes from wrapping in <p>...</p> tags
add_filter( 'widget_text', 'do_shortcode' ); // Allow shortcodes in widgets
add_filter( 'widget_text', 'shortcode_unautop' ); // Prevent shortcodes in widgets from wrapping in <p>...</p> tags
@alexmustin
alexmustin / functions.php
Created April 2, 2020 19:53
Snippet - function to Increase/Decrease brightness of a HEX color by a percentage
<?php
/**
* Increases or decreases the brightness of a color by a percentage of the current brightness.
*
* Credit: https://stackoverflow.com/a/54393956/4256497
*
* @param string $hex_code Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
* @param float $adjust_pct A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
*
@alexmustin
alexmustin / plugin.php
Last active March 19, 2020 00:23
WordPress - Disable Admin Notification of User Password Change
<?php
/**
* Disable Admin Notification of User Password Change
*
* Credit: https://wordpress.stackexchange.com/a/266006/67466
*
* Suppressing this email notification has to be handled
* with a plugin because pluggable.php is loaded earlier
* than a theme's functions.php file.
@alexmustin
alexmustin / functions.php
Created March 2, 2020 22:13
Enable "Dark Mode" in WordPress Gutenberg Block Editor
<?php
// Use Dark Mode in Block Editor.
add_theme_support( 'dark-editor-style' );
?>
@alexmustin
alexmustin / functions.php
Created April 25, 2019 23:42
PHP function to Convert Hex Colors to RGBA
<?php
//* Function to convert Hex colors to RGBA
function hex2rgba( $color, $opacity = false ) {
$defaultColor = 'rgb(0,0,0)';
// Return default color if no color provided
if ( empty( $color ) ) {
return $defaultColor;
@alexmustin
alexmustin / functions.php
Last active April 22, 2019 19:50
Gutenberg - make Button blocks open links in a new window
<?php
//* Enqueue Script
add_action( 'wp_enqueue_scripts', 'yourtheme_enqueue_globaljs_script' );
function yourtheme_enqueue_globaljs_script() {
wp_enqueue_script( 'global-js', get_stylesheet_directory_uri() . "/global.js", array( 'jquery' ), '1.0', true );
}
@alexmustin
alexmustin / shortcodes.php
Last active April 16, 2019 18:08
Simple Shortcode to display a Featured Page or Post
<?php
/**
* This code adds a custom Shortcode to display a "Featured Post."
*/
function featuredpost_shortcode( $atts ) {
// Var defaults
$defaults['id'] = 1;
$postID = '';