- This topic has 6 replies, 2 voices, and was last updated 5 years, 11 months ago by Tom.
-
AuthorPosts
-
May 12, 2018 at 4:32 pm #574173Zad
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.'; }
May 12, 2018 at 9:02 pm #574229TomLead DeveloperLead DeveloperThat’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.'; }
May 12, 2018 at 9:20 pm #574237ZadThat 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();
May 13, 2018 at 9:06 am #574498TomLead DeveloperLead DeveloperAnd you’re sure the code snippet is activated? That code should definitely work, especially when hooked into
after_setup_theme
.May 13, 2018 at 12:12 pm #574581ZadYeah, it is activated and still not working. It was working the first time I implemented it! ๐
May 13, 2018 at 12:33 pm #574592ZadOH 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!
May 13, 2018 at 9:25 pm #574763TomLead DeveloperLead DeveloperNo problem! ๐
-
AuthorPosts
- You must be logged in to reply to this topic.