The monster list of links and code snippets

Originally published: 1st Feb 2021 | Last modified: 7th Apr 2021

I’ve worked on WordPress themes ancient and current, premium and free(mium), but I’m currently handling mostly Divi and Astra projects these days. I keep a file on my desktop with bits and bobs that I reference over and over for different purposesmostly to jog my admittedly poor memory. In the interest of both backing up this file and sharing, here ya go:

General

25 Useful Tricks for the WordPress Functions File via WP Beginner

Displaying SVG inline via Stackoverflow

A stupidly useful old-school shortcode for getting site title, URL, etc. via CSS Tricks

Tim Whitlock’s tool for getting the unicode value of special characters

Cool stuff it’s safe to do with CSS in 2021 via Smashing Magazine

Gutenberg/Blocks

Gutenberg block filters via WordPress Block Editor Handbook

David Gwyer’s deep dives into manipulating blocks

Passing formatting attributes to block templates in PHP

Accessibility/SEO/Technical SEO

Get help writing image alt text via w3

Simon Hearne on preventing layout shifts with font display

Google’s Structured Data helper tool

Some no-plugin-needed, advanced performance tools for WordPress via GeekFlare

A Stackoverflow conversation about dequeuing specific scripts in WordPress

Divi

Divi’s icon font character codes via Divi Dezigns

Astra

Visual Astra theme hooks reference

Exhaustive Astra theme hooks reference

Change Astra’s default breakpoints via WP Astra

Code

CSS

/* Enable smooth scrolling natively in CSS */
html {
  scroll-behavior: smooth;
}
/* specify a custom icon for buttons + read more links that inherits the button text color */
/* .read-more a:after,
.wp-block-button .wp-block-button__link:after {
    content: "[add icon code starting with \]";
    font-family: "Your Icon Font Name";
	margin-left: .5em;
	font-weight: normal;
} */

PHP

// Got a shortcode that's dumping content outside the expected container? Might need to buffer it.

function prefix_archive_description_shortcode() {
	// start buffer
	ob_start();

	// a function call to something like a template part or category description, gets added to buffered output and doesn't necessarily need to be assigned to a variable.

	// return buffered output
	return ob_get_clean();

}
add_shortcode('category_description', 'prefix_archive_description_shortcode');

// Read more: https://konstantin.blog/2013/get_template_part-within-shortcodes/
<!-- Show all the files called in a formatted list. -->
<pre>
    <?php
    $files = get_included_files();
    var_dump( $files );
    ?>
</pre>

<?php
// Run a short jQuery script from functions.php
add_action( 'wp_footer', function() {
    // Checks what page you're on before running script
    if( is_page( 'Cart' ) ) { ?>
        <script>
            ( function( $ ) {
                'use strict';
                $( document ).on( 'ready', function() {

                    // add js or jquery here

                } );
            } ( jQuery ) );
        </script> <?php
    }
} );
// Anything (site name, url, css file path, etc.) that can be accessed via get_bloginfo(). Example shortcodes: [siteinfo key='name'] [siteinfo key='url']

function prefix_bloginfo_shortcode( $atts ) {
   extract(shortcode_atts(array(
       'key' => '',
   ), $atts));
   return get_bloginfo($key);
}
add_shortcode('siteinfo', 'prefix_bloginfo_shortcode');
// Makes login errors more generic to make life a little harder for would-be hackers
function prefix_no_wordpress_errors(){
  return 'Something is wrong! Please check your login info for errors.';
}
add_filter( 'login_errors', 'prefix_no_wordpress_errors' );
// Shortcode to output an SVG inline
function prefix_icon_shortcode () {	
	$url = 'http://dmecorp.wpengine.com/wp-content/uploads/arrow-alt-circle-right-regular.svg';
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
	$svg = curl_exec($ch);
	curl_close($ch);

	return $svg;
}
add_shortcode('custom_icon', 'prefix_icon_shortcode');

Fin.