Skip to content

Instantly share code, notes, and snippets.

@rickrduncan rickrduncan/404.php
Created Jul 5, 2013

Embed
What would you like to do?
404 page temple for the Genesis Framework. Includes a test for the Yoast SEO plugin in order to alter the page title.
<?php
/*
Template Name: Error 404
*/
/**
* Handles the display of website 404 page. Includes a widget area for easy customization.
*
* @author B3Marketing, LLC — Rick R. Duncan
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link http://www.digitalredeye.com
*/
// Add Noindex tag to the page
add_action( 'genesis_meta', 'b3m_noindex_page' );
function b3m_noindex_page() {
echo '<meta name="robots" content="noindex, follow">';
}
// Add canonical tag to the page
add_action( 'genesis_meta', 'b3m_canonical' );
function b3m_canonical() {
echo '<link rel="canonical" href="'.get_site_url().'/404" />';
}
// Output <title> tag. Test for Yoast SEO Plugin
function b3m_set_page_title($orig_title) {
$title = 'Error 404: File Not Found';
return $title;
}
if ( genesis_detect_seo_plugins(array('wpSEO')) ) {
add_filter('wpseo_title', 'b3m_set_page_title');
}
else {
add_filter('wp_title', 'b3m_set_page_title');
}
// Remove default loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'custom_genesis_404' );
function custom_genesis_404() { ?>
<div class="page hentry">
<h1 class="entry-title"><?php _e( 'Error 404: File Not Found', 'genesis' ); ?></h1>
<div class="entry-content">
<?php
if ( is_active_sidebar( '404-page' ) ) {
echo '<div class="entry-content">';
dynamic_sidebar( '404-page' );
echo '</div><!-- end .entry-content -->';
}
else {
genesis_standard_loop();
}
?>
</div><!-- end .entry-content -->
</div><!-- end .pageclass -->
<?php }
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.