Currently reading: Stories of Your Life and Others by Ted Chiang

Add a keyboard shortcut to preview a WordPress post in a new tab [updated]

I use post previews constantly. There's a reason I wrote code to move my drafts and scheduled posts to the top of the posts list! Imagine my disappointment, then, when I didn't see any keyboard shortcuts within Gutenberg to open a post preview in a new tab. Well, as I'm a big fan of userscripts,… Continue reading Add a keyboard shortcut to preview a WordPress post in a new tab [updated]

Blinded by the light!

Does writing on GDocs have your eyeballs feeling a "closeup in Spongebob" sort of way? Try this! First, install the Stylus extension if you haven't already. Remember, though, to get Stylus and not Stylish as the latter was bought out and injected with spyware. That's a whole can of worms you can read about if… Continue reading Blinded by the light!

Get a list of all WordPress hooks that have run

In order to truly catch them all, we can use a "must-use" plugin. These live in the /wp-content/mu-plugins folder as flat PHP files that are automatically included, in alphabetical order, before much has happened in the WordPress core loading process. Normal plugins load fairly early, but these are pulled in even earlier. Their inclusion can't… Continue reading Get a list of all WordPress hooks that have run

WordPress shortcodes don't need fully-qualified parameters

In other words, you don't need to do something like this… …because the shorter way will work just fine. Instead of a named array, the passed parameters will simply be a standard numerically-indexed array ⸺ i.e. a "list" in PHP parlance. Nice, eh? All you have to do is account for one or more of… Continue reading WordPress shortcodes don't need fully-qualified parameters

Nested pages cannot be found with WP_Query

It's hard to believe, I know, but despite its massive list of available parameters, WP_Query somehow doesn't seem to have the tools available to look for grandchildren (and beyond) when querying hierarchical post types. Due to it only supporting the post_parent field, you end up having to nest queries, use custom SQL, or use post__in… Continue reading Nested pages cannot be found with WP_Query

Get the WordPress document title with less work (maybe)

Reusable hero or banner partials often require more robust title-sniffing operations given to their placement inside or outside of The Loop™. In these, a simple the_title() call sometimes won't suffice, so you'll have to figure out what kind of view you're looking at and adjust the title accordingly. If you don't want to do all… Continue reading Get the WordPress document title with less work (maybe)

Use ACF posts as though you're in The Loop™

Imagine that you've got a bunch of template partials calling the usual parameter-less WP templating functions, e.g. the_title(), that automatically use the "current" post as its data source. Everything's peachy until you need to add some related posts to the mix via ACF. You go to reuse some of those partials only to find they… Continue reading Use ACF posts as though you're in The Loop™

Add WordPress and ACF stubs to Intelephense in VS Code

As far as I can tell, WordPress support is built into the PHP language server called Intelephense, but you've got to enable it. Open Code's preferences and type "stubs" into the search bar. Under Intelephense: Stubs, scroll all the way to the bottom of the list to hit the Add Item button. Scroll some more… Continue reading Add WordPress and ACF stubs to Intelephense in VS Code

Move your WordPress theme's templates into a subdirectory

Building on our (mostly unnecessary) add_filters() function to attach a callback to multiple hooks at once, we can adjust how WP's template hierarchy works. Yes, page-specific templates could already go in a `page-templates` directory, but this hook lets all of your templates go into a directory of your choosing. A bit fussy, yes, but there… Continue reading Move your WordPress theme's templates into a subdirectory

Attach a callback to multiple hooks at once

I originally had this stuff as a "bonus tip" in the other post about getting drafts and private pages into the parent-choosing drop-downs, but it ended up longer than the main content! If you don't like having random named functions hanging around, like __dropdown_pages_args() in the post above, you can instead wrap add_filter() with your… Continue reading Attach a callback to multiple hooks at once