I'm using the old "2021" theme as a parent theme for this site. Why? Because it's the last of the default themes not based in Gutenberg blocks. So-called "classic" themes are the best themes. Fight me. Anyway, this theme has enormous post titles out of the box for whatever reason ⸺ the trend of the… Continue reading WordPress rewrites your editor styles… sometimes
Category: Code
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]
Resize images with WordPress's image editor in PHP
Say you've got a list of external images to output that may be huge and mongous. In my case it was images of houses up for rent from a big-ass XML feed. It's unwise to serve these images up directly to users given that huge payloads are generally frowned upon. What you need, then, is… Continue reading Resize images with WordPress's image editor in PHP
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!
Debug PHP variables discreetly
If you don't have Xdebug involved in your current project, you may be relying on var_dump or var_export to check on things while coding. Depending on where in the code this happens, their output can get in the way of the rendering of a given page or be hard to read given where it lands… Continue reading Debug PHP variables discreetly
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)
Find the current (or not) WordPress "no content" release
It's oddly difficult to find the "no content" package of a WP release when you need to manually update a site ⸺ at least it was the last time I went poking around for it. Why would I need to do this when WP offers a perfectly good (and ofttimes automatic) update system? Well, it's… Continue reading Find the current (or not) WordPress "no content" release
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