Created
July 5, 2013 14:46
-
-
Save rickrduncan/5935041 to your computer and use it in GitHub Desktop.
404 page temple for the Genesis Framework. Includes a test for the Yoast SEO plugin in order to alter the page title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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