Site logo

Archived topic

Header element for search pages

13 replies · Started by nomadiceman on August 1, 2021

Viewing posts 1–14 of 14

How can I change the header element for the search page

Currently it’s pulling in the top posts title

Is there a way to get the title in the header element for the “ Search Results for:……”?

Hi there,

Not exactly sure what you mean.

Are you trying to place a " Search Results for: " string on the Header element?

If yes, we'll need a shortcode for that.

Try adding this PHP snippet:

add_shortcode('header_element_search',function(){
	printf(
		/* translators: 1: Search query name */
		__( 'Search Results for: %s', 'generatepress' ),
		'<span>' . get_search_query() . '</span>'
	);
});

And then add the shortcode [header_element_search] to your Header Element's code area.

And if you want to remove the default search result for string, try Tom's suggestion here - https://generatepress.com/forums/topic/removing-search-results-for-from-archive-title/#post-901642

thank you I will give that a try

No problem. Let us know how it goes. :D

Hello Elvin!
Where/ how do I add the [header element search] shortcode to my Header Element’s code area. My picture shows what I tried, but it doesn't work.

Hi there,

you don't add it to the Dynamic Data.
Just add a normal Headline Block and paste the shortcode as the headlines text

Thanks David for the reply: that sounds easy, but I'm desperate.
If I enter the shortcode in the headline (see picture), the result will be written, but it will appear in the wrong place (see picture).
By the way: it works on a normal page, but not in the element.
What am I doing wrong? I found many confusing answers in GP support, but there was no solution.

Try changing the shortcode's php to this:

add_shortcode('header_element_search',function(){
	    ob_start();
    
	printf(
		/* translators: 1: Search query name */
		__( 'Search Results for: %s', 'generatepress' ),
		'<span>' . get_search_query() . '</span>'
	);
	return ob_get_clean();
});

And then add the shortcode as the actual text of the GB Headline block -
https://share.getcloudapp.com/BludbDd9

Thanks Elvin,
the corrected shortcode works fine (see example search on my website). Unfortunately, the title "Search results for:" is present twice. I've tried Tom's Filter (and others) and CSS, the titles stay twice.
Do you have an idea what I can do?

Try this CSS:

body.search header.page-header {
    display: none;
}

Thanks david,
I used exactly this CSS in the customer, but it stays the same: The title appears twice (see example search on my website).
Do you have another idea??

Can you move that CSS to the very top of the Customizer CSS

Dear David,
Great! I would never have come up with this obvious solution. With this I can finally complete my project "New header for the search result page".
Thanks for the great and super fast service from GeneratePress.

Glad to be of help

This archived topic is closed to new replies.