I have created custom rewrite rules. These rules now go to 404 page as expected. I can use action hook template_redirect
to change the template matching query_var
.
But I don’t want to create separate template files as the page structure depend on the current theme in use. Rather I just want to change the content and title. I have tried change the content using the_content
filter, but it seems the filter doesn’t even get called for 404 page.
I also tried loading index.php
template and then using the_content
filter, but it also doesn’t work.
Is there any way to achieve this?
I have a 404 plugin that does basically what you’re needing (if I understand correctly), only it creates a new page (using the same templates from your theme) and registers it as the 404 page. If you already have an existing WordPress page (NOT php file) then you could use code similar to the following to turn it into your new 404 page. Note: You do need to customize this a bit. See the notes in the code below.
If you want to checkout the full plugin code you can do so here: http://wordpress.org/plugins/404-silent-salesman/
Hope that helps!
It seems it is not possible from WordPress point of view as @Milo pointed out
So, I had to change my plan. From the plugin admin, I kept an option to integrate a page as handler for all the request and sending different content matching query variables.