Forums

[resolved] Custom 404 Page Reading Option (5 posts)

  1. ronnieg
    Member
    Posted 5 months ago #

    Would like to see a standard "Reading" option for specifying a static page to be used for the WP custom 404 page content. re: http://codex.wordpress.org/Creating_an_Error_404_Page. If that option is set, the 404.php page would use its content instead of content having to be hard coded in the 404.php page. For example, I manually added an option 'cms_custom_404_page' with the post ID of my 404 page, then in my 404.php (a copy of my site's page template), I include its content with this simple code:

    <?php
    $cms_404_content = null;
    $cms_custom_404_page = get_option('cms_custom_404_page');
    if ( $cms_custom_404_page != null ) {
        $cms_404_content = $cms_custom_404_page->post_content;
       }
    if ( $cms_404_content == null ) {
        echo "<h1>404 - Page Not Found</h1>";
        }
    else {
        echo $cms_404_content;
        }
    ?>

    Now I, or my clients, can simply update the custom 404 page content from the using the normal page editor, without requiring any hacks to the 404.php page.

  2. ronnieg
    Member
    Posted 5 months ago #

    Oops! Missed a step! Should be:

    <?php
    $cms_404_content = null;
    $cms_custom_404_page = get_option('cms_custom_404_page');
    if ( $cms_custom_404_page != null ) {
        $cms_404_post = get_post($cms_custom_404_page);
        $cms_404_content = $cms_404_post->post_content;
       }
    if ( $cms_404_content == null ) {
        echo "<h1>404 - Page Not Found</h1>";
        }
    else {
        echo $cms_404_content;
        }
    ?>
  3. goggans
    Member
    Posted 3 months ago #

    This is a MUCH better solution than the default method!

    How do you add the option for 'cms_custom_404_page' with the post ID of my 404 page?

    Thanks for your help!

  4. ronnieg
    Member
    Posted 3 months ago #

    re, in my original post:
    "I manually added an option 'cms_custom_404_page' with the post ID of my 404 page"
    I did that by using phpMyAdmin to add a new row to the wp_options table with option_name=cms_custom_404_page and option_value=postID of the new 404 page.

  5. goggans
    Member
    Posted 3 months ago #

    Thanks!

Reply

You must log in to post.

About this Topic