Where is the best part to hijack or catch a potential 404

It’s not possible to catch a non–match to template in WP because it will always match some template. The very last template it will fall back to will simply be index.php, the most generic one in template hierarchy.

In general the appropriate hook for such logic is typically template_redirect in template-loader.php. At this point the query is done, the conditional context is fully set up, but native template resolution and inclusion hadn’t fired yet.

Leave a Comment