Archived topic
Dynamic Search Header
8 replies · Started by Ivan on May 1, 2021
Hi guys,
I just updated to GP Premium 2.0.1 and managed to make an archive page with dynamic category names! Great!
How can I do the same for the search page? Please see the links below. Instead of the three green dots I would like to show the search term. Additionally, I would like to remove the default box saying (Search Results for: ). Hope this will be possible.
Thank you!
Could you please let me know whether this can be done? Thanks!
Hi there,
Give this a shot:
add_filter( 'generate_dynamic_element_text', function( $text, $block ) {
if ( is_search() && 'Your Search Title' === $block['attrs']['gpDynamicTextReplace'] ) {
$text = get_search_query();
}
return $text;
}, 10, 2 );
Then you just need to update Your Search Title with the text you've added to the Headline block of the actual Block Element.
Let us know :)
Hi Tom,
Thanks a lot! I thought there was something in the dynamic options that I am missing...
Do you plan to add this to one of the next GP Premium releases? I would prefer not to add custom PHP if possible. :)
Thank you!
Hi there,
Point releases (2.0.x) are only for bug fixes, so if we do add this (seems like a good addition), it will be in 2.1.0.
However, the above code is a filter, so it's 100% update-safe and can simply be removed once the functionality is added to the plugin :)
Thanks Tom!
Hope you will add this to the plugin. :)
Cheers,
Ivan
Took a look at this. We'll be adding it to 2.1.0 once GP 3.1.0 is out (as it's not possible to remove the default search page title as of right now).
Thanks!
Awesome! Thank you, Tom!
No problem!