I know you're not "supposed" to debug things by outputting them into or past the footer of a site, but sometimes you just need to check on something real quick, like the ID or some other bit of data about a post, and you don't feel like dealing with any proper debugging tools. The wp_footer hook then gets used and the results don't make sense. What happened?
Tag: hooks
Enqueue inline JS at the WordPress footer hook
WooCommerce has a handy function you might like to include in your toolbag even when that plugin isn't in play: wc_enqueue_js(). It takes a string of JS code, wraps it in jQuery, outputs it in the footer of your site, and runs it when the DOMContentLoaded event fires. Neat? I guess!
Keep on readin' on Enqueue inline JS at the WordPress footer hook⟶
You can't filter meta data in WordPress for some reason
By that I mean that the handy and heavily-used get_post_meta() function, and the get_metadata() function for which the former is a wrapper, do not call apply_filters() on the data they return. Of all the places I've found lacking support for hooks, this one is perhaps the most infuriating.
Keep on readin' on You can't filter meta data in WordPress for some reason⟶
Pulling your color palette from theme.json into ACF color pickers
I'm not sure why ACF doesn't do this by default as it seems like something of a no-brainer. If a given theme has a color palette set, why wouldn't the user want that palette available in each color picker? Seems like an obvious and easy win to me.
Keep on readin' on Pulling your color palette from theme.json into ACF color pickers⟶
Simpler WordPress Ajax calls
This has been possible for years, but it's hard to know everything, you know? That's especially true when the thing you want to use isn't even documented and it's up to your fellow nerds to figure it out.
WordPress rewrites your editor styles… sometimes
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.
Keep on readin' on WordPress rewrites your editor styles… sometimes⟶
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.
Keep on readin' on Get a list of all WordPress hooks that have run⟶
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.
Keep on readin' on Get the WordPress document title with less work (maybe)⟶
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.
Keep on readin' on 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!
Keep on readin' on Attach a callback to multiple hooks at once⟶