Site logo

Archived topic

Remove default content in search page

1 reply · Started by Raffaele Salvemini on January 23, 2023

Viewing posts 1–2 of 2

Hi, I need to remove the default code in the search result page.

I will add my custom code, but I cannot find a way to completely remove the default code, it there a PHP code to do it?

Thanks a lot!

Hi there,

in the theme archive and search templates we add the generate_has_default_loop function:

https://github.com/tomusborne/generatepress/blob/e7fbf5693bfe4325a41cae988e3eda16550d4025/search.php#L24

Which you can use to disable the themes loop like so:

add_filter( 'generate_has_default_loop', function(){
    if ( is_search() ) {
        return false;
    }
    return true;
});

Then you can use the generate_before_main_content or the generate_after_main_content hooks to add in your own code.

Let me know if you need more info

This archived topic is closed to new replies.