Site logo

Archived topic

Remove search from 404 page

9 replies · Started by Sebastian on January 21, 2018

Viewing posts 1–10 of 10

Hi Tom,

could you please tell me how exactly I have to write the code to remove the search function from the 404 page?

I don't want to use a custom 404 page via plugin, just want to get rid of the search form from the native 404 page.
Thank youuu.

Hi Leo,

thank you for your help.

That fixed that.
Though I was expecting to modify the functions.php but this styling does the trick perfectly.
Thank you very much.

No problem!

I know this is an old topic, but if anyone is looking to remove the search box from 404 pages and not just hide it with css, the following snippet does the trick.

add_filter( 'generate_404_text','generate_custom_404_text' );
function generate_custom_404_text()
{
    return '';
}
add_filter( 'get_search_form','my_remove_search_form' );
function my_remove_search_form()
{
    $template = $GLOBALS['template'];
    $template_file = substr($template, strrpos($template, '/') + 1);
    if ($template_file === '404.php') {
        return '';
    }
}

Thanks for sharing!

Leo, your CSS works perfectly for removing the search bar that's in the body of my 404 page, but unfortunately it also deactivates the search bar in the header (the header search bar is global but only the 404 header search bar is negatively affected). Can you help me fix this?

Hi Luke,

Try this CSS:

.error404 .site-main form.search-form{
    display: none;
}

This worked perfectly, thank you Ying

You are welcome Luke :)

This archived topic is closed to new replies.