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 ⸺ in one part of a three-column block, for instance.
Tag: php
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⟶
WordPress shortcodes don't need fully-qualified parameters
In other words, you don't need to do something like this...
Keep on readin' on 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 with a secondary call of some sort to fill the "in" set of posts through which WP_Query will look.
Keep on readin' on 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.
Keep on readin' on 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.
Keep on readin' on 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.
Keep on readin' on 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.
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⟶
Add private and drafted pages to parent drop-down lists
I'm sure that in most cases the default behavior of only showing published pages is probably what you want. Who needs a bunch of outdated or unfinished pages cluttering these lists, right?
Keep on readin' on Add private and drafted pages to parent drop-down lists⟶