[Resolved] Remove search from 404 page

Home Forums Support Remove search from 404 page

Viewing 6 posts - 1 through 6 (of 6 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.

    GeneratePress 2.0.2
    GP Premium 1.5.6
    #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
    #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
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.