The WordPress theme I am using didn’t come with a proper Error 404 handler and I’d like to add one to the code. I am having a hard time how WordPress determines if a URL does exist as a post, is a search query, or doesn’t exist. I’d like to know where the code WordPress uses is located, or how WordPress determines this as I need to implicate it in the theme files.
2 comments
Comments are closed.
You don’t need to add anything special to the top of 404.php. WordPress will know to use 404.php automatically when it tries to get a post or page and fails.
To create a custom 404 page for a theme, the simplest way is to:
I highly recommend taking a look at the 404.php that comes with the TwentyTwelve, TwentyThirteen (etc.) themes to get a grasp of how WordPress 404 error pages work.
I’ve never personally had a problem with WordPress being unable to tell a URL doesn’t exist, but if you want to make absolutely sure your web server returns your custom 404.php when a page can’t be found, add the following line to .htaccess in the main folder where index.php is:
Just change the URL accordingly if you have WordPress installed in a subdirectory.
I hope this helps a little. Good luck!
Why do you want to customize the 404’s core.
One theme always has a file 404.php. You can do normally everything and display in this page
(Get some post, images,link, tag….).
If you want add a hook, try this: Are there any hooks that alter the 404 logic?
Good luck.