-
Wolfgang
I would like to customize the search-result-page. I didn’t find any answers in the forum so far.
I would like to customize the upper section of the page, adjusting margins, typography and the generated text that says something like “your search results for:”.
I made a page-hero-element. I can now adjust margins, but I don’t know how to change and design the automatically generated search-result text. Is it possible to make a “H”-block in which I could put a custom text and where I could add the “search-text”-variable?
In that case I would also need the standard-text to vanish. I tried “disable title” but this has no effect.
Thank you!
-
Fernando
1. Create a Block Element – Page Hero. Display it to the Search results page.
2. Add a Headline Block.
3. Give this block a class of
hero-title
.
Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/4. Enable the dynamic options in the toolbar to get the title.
5 Add this snippet:
add_filter( 'generate_dynamic_element_text', function( $text, $block ) { if ( is_search() && ! empty( $block['attrs']['className'] ) && 'hero-title' === $block['attrs']['className'] ) { $text = 'Your search results for:' . get_search_query(); } return $text; }, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
-
Wolfgang
This works fine, thank you!
Now I would need to remove the old page-title. I selected “disable title” but this has no effect.
-
Hi there,
it requires some PHP:
add_action('wp', function() { remove_action( 'generate_before_loop', 'generate_do_search_results_title' ); });
-
Wolfgang
Thanks a lot David, this works fine.
Now, what would I need to change in the two php-snipplets to customize the “no results”-page the same way?
-
The NO Results page, you can just use a Block Element -> Loop Template and this will override the entire page.
-
Wolfgang
Perfect, thank you!
So what about the 404-page? Any chance to customize that as well? (remove standard texts/add editable block)?
-
Yeah, for that you can use a Content Template and it will replace the entire thing.
-
Wolfgang
Thank you so much!
-
You’re welcome
- You must be logged in to reply to this topic.