You can edit any page imaginable in WordPress, except the 404 error page. Usually the 404 error page is only editable by opening up the 404.php file in your WordPress theme directory and changing the content that way. There are plugins which allow you to have custom 404 pages, but there is no point in using plugins if you can do it easily yourself.
Wouldn’t it just be simpler if you could edit your 404 page from within the pages menu in the WordPress dashboard? Well, you can.
In your functions.php file (located in your theme folder) add the following code:
// Ensures this function is only called after the theme is setup
// You could bind to the "init" event if "after_setup_theme" doesn't work well for you.
add_action('after_setup_theme', 'create_404_page');
// Insert a privately published page we can query for our 404 page
function create_404_page() {
// Check if the 404 page exists
$page_exists = get_page_by_title( '404' );
if (!isset($page_exists->ID)) {
// Page array
$page = array(
'post_author' => 1,
'post_content' => '',
'post_name' => '404',
'post_status' => 'private',
'post_title' => '404',
'post_type' => 'page',
'post_parent' => 0,
'menu_order' => 0,
'to_ping' => '',
'pinged' => '',
);
$insert = wp_insert_post($page);
// The insert was successful
if ($insert) {
// Store the value of our 404 page
update_option( '404pageid', (int) $insert );
}
}
}
In your 404.php file (located in your theme folder) add the following code:
post_content) && trim($the_page->post_content == '')): ?>
There was an error and nobody defined a custom 404 page message, so you're seeing this instead.
post_content ); ?>
You should now have a 404 page in the backend when edit is added to, is displayed whenever someone hits your 404 page. You can take things a step further and define sidebars and custom widgetised areas so you can display search widgets and anything else you like.