[Resolved] Remove search from 404 page

Home Forums Support [Resolved] Remove search from 404 page

Home Forums Support Remove search from 404 page

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #476478
    Sebastian

    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.

    #476638
    Leo
    Staff
    Customer Support

    Hi there,

    Try this CSS:

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

    Adding CSS: https://docs.generatepress.com/article/adding-css/

    #476676
    Sebastian

    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.

    #476707
    Leo
    Staff
    Customer Support

    No problem!

    #1012045
    Marquis M

    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 '';
        }
    }
    #1012051
    Leo
    Staff
    Customer Support

    Thanks for sharing!

    #1949761
    Luke

    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?

    #1949795
    Ying
    Staff
    Customer Support

    Hi Luke,

    Try this CSS:

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

    This worked perfectly, thank you Ying

    #1950669
    Ying
    Staff
    Customer Support

    You are welcome Luke 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.