While working on another post, I had some very large tables and I wanted to use Bootstrap Responsive Tables by adding the .table-responsive class but only in the situation where the table is too wide. This is the code I used.
WordPress
How to Set Older WordPress Posts to Draft with WP CLI
In one of the slack channels I follow, the question came up on how to set WordPress posts older than a certain date to “draft” status using with WP CLI. I was surprised by how difficult I found this task and wanted to document my solution.
ACF Uncaught TypeError: Cannot read property ‘id’ of undefined
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 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.