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

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

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)

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

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? But what about the case where you're trying to create a bunch of pages all at once, a series of related and therefore… Continue reading Add private and drafted pages to parent drop-down lists

Move drafts to the top of your WordPress posts list

This isn't something WP supports by default as it has a strict list of available options for its orderby parameter and post_status ain't one of 'em. Well, let's fix that. Yes, your posts drafts will probably be near the top anyway with the default descending date sorting, but sometimes things fall behind. Your page drafts,… Continue reading Move drafts to the top of your WordPress posts list