October 2019

How to set defer or async attributes on enqueued script tags in WordPress

If you get down to business with performance optimisation, you could find yourself looking at ways to defer your scripts or even load them asynchronously. As far as I'm aware, WordPress' built-in functions wp_register_script() and wp_enqueue_script() don't currently take arguments for defining these attributes. But, with WordPress being WordPress, there is usually a way and […]

October 2019

Working with empty jQuery objects to build dynamic selectors

This is one of those techniques that you don't really think you need until you find yourself in a situation where you do. This definitely isn't a hammer and more often than not, you can select what you need in a single selector via jQuery or through the use of the built-in .filter() method but […]

October 2019

How to customize the colour palette for WordPress' Gutenberg block editor

Building on yesterday's tip, I'm putting this up to show how easy it is to register a custom colour palette for WordPress' block editor; AKA Gutenberg. It's actually something we can register as a theme feature so it's all doable on the PHP side and is very straight-forward. Here's the code you need;

October 2019

How to customize the colour palette for ACF's colour picker field

Ever found yourself wishing you could define an exact colour palette for ACF's colour picker field? Good news! You totally can. Using the JavaScript API built right into Advanced Custom Fields we can use a very small snippet of code to specify exactly which colours appear in the palette of suggested colours. Now, in this […]

October 2019

Cache jQuery selectors for more efficient JavaScript

Having worked in collaborative and team contexts, I've had my fair share of situations where I'm working in amongst someone else's code. There are plenty of things I could gab on about but one issue I commonly see is duplicate jQuery selectors. Now, for really small scripts, duplicate selectors won't cause you much heartache. However, […]

October 2019

Customise ACF's WYSIWYG field toolbars for a simpler admin experience

The ability to control exactly what buttons are available in a WYSIWYG field is a really neat point of customisation available in Advanced Custom Fields. The WYSIWYG field is definitely convenient but I often find myself needing to use it for no other reason than the most basic of formatting. Leaving too many options in […]

October 2019

Use WP CLI to tinker with your codebase via an interactive shell

If you have access to WP CLI I can't recommend it enough. Since I picked it up it has saved me so much time during development. It helps me scaffold code, analyse the installation, update core and plugins, and it even helps me test code on the fly. Testing code on the fly with wp […]

October 2019

How to get Advanced Custom Fields to load JSON files from more than one directory

If you use Advanced Custom Fields a lot you are probably using ACF's very awesome Local JSON feature. By default, ACF saves and loads all JSON files from the acf-json directory inside your theme but it is possible to take control of ACF's behaviour to define your own custom load points as outlined in the […]

October 2019

Use closures for basic encapsulation when writing jQuery

If you are writing a lot of jQuery you'll likely have files with loads of JavaScript functions and variables that may be completely independent and shouldn't interfere with each other. If you have a lot of this going on (or even if you don't) you might consider wrapping up related variables & functions using closures […]

October 2019

A function for temporarily changing the WordPress post context

If you've ever found yourself in a situation where you need to render something from some other post whilst in the context of another, you may have ended up just overriding the global $post variable. It works fine but can be problematic where you mess it up or just forget to clean up after yourself. […]