blvdstudios
blvdstudios

Reputation: 21

Change WordPress 404 to a different page

How can I changed where WordPress calls 404.php?

Basically what I want to happen is when WordPress doesn't find a link I want anotherpage.php to be called instead of 404.php.

Thanks

Upvotes: 0

Views: 175

Answers (2)

user488187
user488187

Reputation:

404.php is the WordPress template for displaying something when a page is "Not Found".

The simplest thing would be for you to edit the 404.php template to be what you want (to be the same as anotherpage.php).

If that is not possible, you can add the following to your 404.php template to redirect the page to where you want:

<?php wp_redirect( ‘http://www.example.com/anotherpage.php’, 301 ); exit; ?>

This will send the visitor to the page you want.

Upvotes: 1

Nathan Dawson
Nathan Dawson

Reputation: 19308

Use a filter to override the template that's included.

Example:

function wpse_override_404_template( $template_path ) {
    return locate_template( 'template-to-override-with.php' );
}
add_filter( '404_template', 'wpse_override_404_template' );

This filter is used inside get_query_template(). To find out more take a look at the codex page: http://codex.wordpress.org/Function_Reference/get_query_template

Upvotes: 0

Related Questions