Archived topic
remove "search results"
7 replies · Started by Dominik on August 19, 2021
how to remove the title of the search results? the function below works for categories.
add_action( 'after_setup_theme', function() {
remove_action( 'generate_archive_title', 'generate_archive_title' );
} );
this code works for categories
Hi Dominik,
Give this PHP snippet a try:
add_filter( 'gettext', function( $text ) {
if ( 'Search Results for: %s' === $text ) {
$text = '';
}
return $text;
} );
Let me know :)
Hi Ying, this code does not work. i tried it before
add_filter( 'gettext', function( $text ) {
if ( 'Search Results for: %s' === $text ) {
$text = '';
}
return $text;
} );
I tested it on my site, it works.
How did you add the snippet?
Is there any other custom function that might cause conflicts?
I think so too. I am using "code snippets". I tried disabling other codes but it didn't help.
Hi Dominik,
Instead of completely removing the search result heading/title, would just removing it from display suffice?
If yes, add this CSS:
body.search header.page-header {
display: none;
}
This may be a better solution overall as it prevents SEO related errors like "h1 is missing" while keeping the search title from displaying as removing the search title through PHP will completely remove it from the page source.
thank you
No problem. :D