Last active
May 8, 2018 21:27
-
-
Save anwerashif/6df666d4f07c1a689c2846c2341b4b98 to your computer and use it in GitHub Desktop.
Custom 404 Not Found Page in Genesis Framework
This file contains hidden or 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 | |
/** | |
* 404 NOT FOUND. | |
* | |
* @package StudioPlayer | |
* @link https://rainastudio.com/themes/studioplayer | |
* @author RainaStudio | |
* @copyright Copyright © 2018 RainaStudio | |
* @license GPL-2.0+ | |
*/ | |
// Remove page title. | |
remove_action( 'genesis_post_title', 'genesis_do_post_title' ); | |
// Remove site header elements. | |
remove_action( 'genesis_header', 'genesis_header_markup_open', 5 ); | |
remove_action( 'genesis_header', 'genesis_do_header' ); | |
remove_action( 'genesis_header', 'genesis_header_markup_close', 15 ); | |
// Remove navigation. | |
remove_theme_support( 'genesis-menus' ); | |
// Force full width. | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); | |
// Add 'not-found' class to body. | |
function nf_site_inner_attr( $attributes ) { | |
$attributes['class'] .= ' not-found'; | |
// Add the attributes from .entry, since this replaces the main entry | |
$attributes = wp_parse_args( $attributes, genesis_attributes_entry( array() ) ); | |
return $attributes; | |
} | |
add_filter( 'genesis_attr_body', 'nf_site_inner_attr' ); | |
// Remove default loop. | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
// Add content to default loop. | |
/** | |
* This function outputs a 404 "Not Found" error message. | |
* | |
* @since 1.6 | |
*/ | |
function genesis_404() { | |
genesis_markup( array( | |
'open' => '<article class="entry">', | |
'context' => 'entry-404', | |
) ); | |
printf( '<h1 class="entry-title"><i class="fa fa-life-ring"></i> %s</h1>', apply_filters( 'genesis_404_entry_title', __( '404 Not Found!', 'genesis' ) ) ); | |
echo '<div class="entry-content">'; | |
?> | |
<p>Server can't find your query at <?php echo $_SERVER["SERVER_NAME"]; ?>. In the meantime, you can...</p> | |
<ul> | |
<li>See what's happening at <?php echo get_bloginfo( 'name' ); ?> on <a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>">our awesome blog.</a></li> | |
<li>Read more about our project on <a href="https://rainastudio.com/service/">the service page.</a></li> | |
<li>Sign up for newsletter and join the community!</li> | |
</ul> | |
<div class="not-found-widget"><?php | |
if ( is_active_sidebar('not-found-widget')) { | |
// 404 page widget area. | |
genesis_widget_area( 'not-found-widget', array( | |
'before' => '<div class="not-found-widget widget-area clearfix"><div class="wrap">', | |
'after' => '</div></div>', | |
) ); | |
} | |
?></div> | |
<?php | |
echo '</div>'; | |
genesis_markup( array( | |
'close' => '</article>', | |
'context' => 'entry-404', | |
) ); | |
} | |
add_action( 'genesis_loop', 'genesis_404' ); | |
// Remove footer widgets. | |
remove_theme_support( 'genesis-footer-widgets' ); | |
// Remove site footer elements. | |
remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 ); | |
remove_action( 'genesis_footer', 'genesis_do_footer' ); | |
remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 ); | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment