• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SomeDevTips

Tips and code examples for software developers

  • WordPress
  • PHP

Genesis: how to customize the 404 page

6 July 2019. Categories: WordPress

When a user enters a url that does not match any page, your site shows the 404 page, that is a page to inform the user that the given url does not correspond to any page in the site.

But why the name “404 page” ? Because when a browser requests a page from a site, the web server that hosts that site sends a response that contains a “status code”. The status code is a number whose value is 200 if the page was found or 404 if that page was not found (for a list of all status codes you can see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ). 

Genesis framework allows to customize both the title and the content of this page by means of two filters:

  • genesis_404_entry_title
  • genesis_404_entry_content

So for example, to customize the title of the page you can use the following code:


add_filter( 'genesis_404_entry_title', 'mytheme_404_entry_title' );
function mytheme_404_entry_title ( $title ) {
    $output = “Page not found on this site";
    return $output;
}

To customize the content of the page after the title you can use the following code:


add_filter( 'genesis_404_entry_content', 'mytheme_404_entry_content' );
function mytheme_404_entry_content( $content ) {
    $homelink = trailingslashit( home_url() );
    $output = <<<TEXT404
        The page you are looking for does not exist. You can go to the 
        <a href="$homelink">home page</a> of the site or you can use the search form below.
TEXT404;
    
    return $output;
}

Primary Sidebar

Recent articles

  • WordPress: let an author manage categories and tags
  • A local development environment for web applications
  • Stacks and queues: features
  • A simple backup script for WordPress
  • Git: how to change the remote repository of a project

Categories

  • Algorithms and data structures
  • PHP
  • Version control
  • Web
  • WordPress

© Copyright 2019-2023 · Somedevtips