I work with WordPress sites that have lots of meta fields exposed through the REST API. Within Gutenberg, I’m often checking those values by querying the “meta” attribute in the data. Sometimes the larger number of meta fields makes it difficult to find the specific fields I’m interested in. To make my life easier, I’ve put together a code snippet that filters the keys in the meta object that is returned.
WordPress
unregisterFormatType() for Specific Block Type in Gutenberg
The WordPress block editor (a.k.a. Gutenberg) allows formatting in RichText fields via the Formatting Toolbar API](. Each type of formatting (e.g. Bold and Italic) is a “formatType”. Here we’ll look at removing one of these formatTypes from a specific block type (e.g. removing Bold from the core paragraph block).
WP CLI Get Current Theme
I thought retrieving the currently active theme on a WordPress website with WP CLI would involve the “wp theme” command but I was wrong. The correct command to get the currently active theme is “wp option get current_theme”.
WP CLI Find in Post
Sometimes I want a list of blog posts that contain a certain string. For example, I might want a list of all blog posts that contain the word “kazoo” using WP CLI. My favorite tool for this is “wp post list”.
Quick and Dirty WP CLI
During development or troubleshooting I often find myself wanting to run something through WP CLI. These are some notes on running code through WP CLI.
WordPress Multisite Skip Confirmation Email
When creating a new user on WordPress multisite there is a “Skip Confirmation Email” checkbox that is unchecked by default. This unchecked box results in a user being added to a temporary “signups list” when they are added to the site. The user is not fully added to the site until they complete the confirmation steps in the email they receive. For many sites, it is preferable to check this “Skip Confirmation Email” when adding a user. With some code you can set this checkbox to default to checked.
How to Close and Re-Open WordPress Gutenberg Sidebar
The sidebar gets a lot of use in the WordPress Block Editor, a.k.a. Gutenberg, but I found myself in a situation where I needed to programmatically close the sidebar and then re-open it later. This is how I did it.
Get Last Modified Value of a WordPress Post
When reading an article online, I find it helpful to know when the article was last updated. Not all blogs display the last updated value however even when the last updated value is not displayed, the value is accessible via the WordPress REST API. This is how I retrieve the last modified value from the WordPress REST API.
Change Render Size of Featured Image in WordPress Gutenberg Block Editor
In the WordPress block editor (a.k.a. Gutenberg) the “Featured Image” is rendered at the WordPress ‘large’ image size by default. By adding a WordPress JavaScript filter to the ‘editor.PostFeaturedImage.imageSize’ hook, we can change this default rendering.
WordPress View Block Attributes
When developing a WordPress plugin that creates a Gutenberg block, it is invaluable to be able to view the attributes on the block. Here are some tricks I use to view this information.