Archived topic
Custom 404 not working
6 replies · Started by Zad on May 12, 2018
I used the following code and pasted it into code snippet to create a custom 404 page. It worked yesterday when I first created it. But now, the custom message no longer seems to be there. Wondering what could've happened?
add_filter( 'generate_404_title','generate_custom_404_title' );
function generate_custom_404_title()
{
return 'Ruh roh!';
}
add_filter( 'generate_404_text','generate_custom_404_text' );
function generate_custom_404_text()
{
return 'Looks like ya done goofed! Try searching again.';
}
That's strange - try this instead:
add_action( 'after_setup_theme', 'tu_change_404_stuff' );
function tu_change_404_stuff() {
add_filter( 'generate_404_title', 'tu_custom_404_title' );
add_filter( 'generate_404_text', 'tu_custom_404_text' );
}
function tu_custom_404_title() {
return 'Ruh roh!';
}
function tu_custom_404_text() {
return 'Looks like ya done goofed! Try searching again.';
}
That didn't seem to work with Code Snippets either. Not sure if something is broken. I looked at the 404.php file, here's the code
<?php
/**
* The template for displaying 404 pages (Not Found).
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header(); ?>
<div id="primary" <?php generate_content_class(); ?>>
<main id="main" <?php generate_main_class(); ?>>
<?php
/**
* generate_before_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_main_content' );
?>
<div class="inside-article">
<?php
/**
* generate_before_content hook.
*
* @since 0.1
*
* @hooked generate_featured_page_header_inside_single - 10
*/
do_action( 'generate_before_content' );
?>
<header class="entry-header">
<h1 class="entry-title" itemprop="headline"><?php echo apply_filters( 'generate_404_title', __( 'Oops! That page can’t be found.', 'generatepress' ) ); // WPCS: XSS OK. ?></h1>
</header><!-- .entry-header -->
<?php
/**
* generate_after_entry_header hook.
*
* @since 0.1
*
* @hooked generate_post_image - 10
*/
do_action( 'generate_after_entry_header' );
?>
<div class="entry-content" itemprop="text">
<?php
echo '<p>' . apply_filters( 'generate_404_text', __( 'It looks like nothing was found at this location. Maybe try searching?', 'generatepress' ) ) . '</p>'; // WPCS: XSS OK.
get_search_form();
?>
</div><!-- .entry-content -->
<?php
/**
* generate_after_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_content' );
?>
</div><!-- .inside-article -->
<?php
/**
* generate_after_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_main_content' );
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
/**
* generate_after_primary_content_area hook.
*
* @since 2.0
*/
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
get_footer();
And you're sure the code snippet is activated? That code should definitely work, especially when hooked into after_setup_theme.
Yeah, it is activated and still not working. It was working the first time I implemented it! :(
OH WAIT! I TOTALLY CONFUSED THEM! I was trying to make the 404 page come up by typing incorrect terms into my search bar but I forgot that the 404 page is for links that are old and no longer there! The custom 404 page comes up when I try to access an old page that's been deleted!
So sorry for my confusion on this!
No problem! :)