Site logo

Archived topic

Delete native 404 message

6 replies · Started by Oliver on September 27, 2021

Viewing posts 1–7 of 7

I created a custom 404 page using a block element that displays as 404 template.
It works nicely but the original Oops! That page can’t be found., doesn´t really go well with the template. specially since the page is in German but the backend will remain in english.

can I remove only the original message from the 404 page?

Hi Oliver,

There are multiple ways to change the default text of the 404 page.

You can either use gettext filter hook to translate the default text,

Example:

add_filter( 'gettext', function( $text ) {
    if ( 'Oops! That page can’t be found.' === $text ) {
        return 'The replacement text here';
    } if ( 'It looks like nothing was found at this location. Maybe try searching?' === $text ) {
        return 'another replacement text here';
    }

    return $text;
} );

Or

You can use generate_404_title filter for the title and generate_404_text if you want to modify the HTML structure completely. :)

Here are the codes involved.

https://github.com/tomusborne/generatepress/blob/2c7c8a76d3b58b0b97e82b3a7a5ebf022a1ddfbe/content-404.php#L27
https://github.com/tomusborne/generatepress/blob/2c7c8a76d3b58b0b97e82b3a7a5ebf022a1ddfbe/content-404.php#L51

Hi Elvin
Thanks for your reply.
I just want to make it not show under the template I created. so make it completely disappear rather than change it. is that possible?

We can use this PHP snippet for that:

add_filter( 'generate_404_title','remove_404_title' );
function remove_404_title()
{
      return '';
}

add_filter( 'generate_404_text','remove_404_text' );
function remove_404_text()
{
      return '';
}

Edit: Or better yet. Use Block Element - Content Template, create your layout and set the display rule location to "404 template" for a better customization experience. :D

Thanks Elvin the php code worked. But the search bar is still showing up. Can we also remove the search bar?

Nevermind, the Block Element – Content Template method is better as you said!
Thanks a lot! have a nice day!

No problem. Glad to be of any help. :D

This archived topic is closed to new replies.