Recently I was working on a site using Advanced Custom Fields (ACF) and the field input boxes had stopped working. In the browser console, I saw the error “ACF Uncaught TypeError: Cannot read property ‘id’ of undefined”.
WordPress
WordPress JavaScript async defer
When loading JavaScript on a webpage with the “script” tag, there are additional attributes you can add to tell the browser how and when to load the JavaScript (‘async’ and ‘defer’). In WordPress, there is not a native way to add these attributes but this code snippet does the trick.
Install a non-wordpress.org Plugin with WP CLI
The WordPress plugin repository at wordpress.org/plugins is a great resource. I often use WP CLI to install plugins on my WordPress site from there, however, sometimes I want to install other plugins with WP CLI.
Override WordPress Publish Date on Creation
When creating new posts for a video demonstration, I wanted to display a consistent date. While my first thought was to reset my system clock, this snippet overrides the date when the post is first created, which worked for me.
WordPress Core Development on Local by Flywheel
I setup a site for WordPress Core development with Local by Flywheel and documented the steps. If you’re trying to do the same, this might be helpful.
Prevent WordPress Auto Embed
In one of my other posts I am displaying some URLs on their own line as part of the content however the WordPress oEmbed functionality is turning these into rich HTML. I was able to suppress this by wrapping the URLs in HTML span tags.
Full Post on Blog Archive
On a WordPress project, I wanted to display the full post on the blog archive unless a manual excerpt had been created for the post (in which case I wanted to use the manual excerpt). Here is the code I used to make this happen.
WordPress Image Array of Attributes
When working with a WordPress image, I wanted the attributes for the image. The function `wp_get_attachment_image()` provides me everything I need but in a rendered HTML string, rather than a more useful array of attributes. I was surprised I was unable to locate a good way to get this information, so I wrote this code to help me.
WordPress Market Share as a Metric of Success
As of this writing, WordPress has a market share of approximately 31%. I often hear people referencing the “goal” of WordPress reaching 51% marketshare. I don’t understand this goal.
Speed Up WordPress Website
Slow websites are painful. An important value to look at when optimizing your website is the TTFB (Time Til First Bye), which is the delay between when the request is sent to the server and server actually responds. These are some of my notes on improving (e.g. reducing) the TTFB of a WordPress website.