Skip to content

Instantly share code, notes, and snippets.

@pamhirsch
Created February 12, 2015 18:31
Show Gist options
  • Save pamhirsch/2da560bc449e352553f8 to your computer and use it in GitHub Desktop.
Save pamhirsch/2da560bc449e352553f8 to your computer and use it in GitHub Desktop.
Custom 404 page for Genesis
<?php
/**
*
* @package LCW\Templates
* @author Pamela Hirsch
* @license GPL-2.0+
* @link http://www.pamelahirsch.com/services
*/
add_action( 'genesis_meta', 'phc_genesis_meta' );
function phc_genesis_meta() {
//* Force content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Add 404 page body class
add_filter( 'body_class', 'phc_body_class' );
}
function phc_body_class( $classes ) {
$classes[] = 'phc-404';
return $classes;
}
//* Remove default loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'phc_404' );
/**
* This function outputs a 404 "Not Found" error message
*
* @since 1.6
*/
function phc_404() {
echo genesis_html5() ? '<article class="entry">' : '<div class="post hentry">';
printf( '<h3>%s</h3>', __( 'We\'re sorry, but the page you\'re looking for no longer exits.', 'genesis' ) );
echo '<div class="entry-content">';
echo '<p>' . sprintf( __( 'Please return to the <a href=" '. $siteurl .'/">homepage</a> and see if you can find what you were looking for.', 'genesis' ), home_url() ) . '</p>';
echo '</div>';
echo genesis_html5() ? '</article>' : '</div>';
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment