- This topic has 5 replies, 3 voices, and was last updated 6 months, 3 weeks ago by
David.
-
AuthorPosts
-
August 31, 2022 at 8:45 am #2329693
Tobias
Hi,
I’ve successfully styled the native WP search results using a Block Element of type Content Template.
A plugin (GeoDirectory) has set up a custom search, that is based on a usual page with a shortcode in it.
Here comes the problem as I understand it:
- The custom search results are included in a normal page that hold a Shortcode. That page begins with an <article> tag.
- The block element styles all <article> elements in search result pages, even in custom searches.
- The result is, the whole custom search page gets the styling (background, colors) of a single search result.
I hope my analysis makes sense. Feel free to ask.
What I need are ideas about how to exclude the content template from custom search pages.
Thanks!
August 31, 2022 at 10:30 am #2329772Ying
StaffCustomer SupportHi Tobias,
Can you show us a custom search page and the default search result page?
Let me know!
September 1, 2022 at 2:16 am #2330241Tobias
Hi Ying,
Please find both links in the private area of this post.
Look at the custom search source code: All content is covered by an article.dynamic-content-template (the template element). It surrounds the search results altogether! The template element applies the content of the last search result to the whole page. There is a hidden image (display:none) above the H2 title of the page, that corresponds to the last search result.
I want to exclude the custom search page completely, because its content is managed by the 3rd party plugin. But excluding “all singular” or “all pages” didn’t do the job.
If there’s a chance to add a feature to elements like “exclude by body-class”, that would be a very versatile solution!
Thanks in advance for taking the time.
September 1, 2022 at 3:15 am #2330307David
StaffCustomer SupportHi there,
you can use the
generate_element_display
filter hook to change the display of an element:https://docs.generatepress.com/article/generate_element_display/
And according to this reply it looks like we can use:
geodir_is_geodir_page()
to check if we’re on a geodir page.So putting it altogether you can use this snippet:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && geodir_is_geodir_page() ) { $display = false; } return $display; }, 10, 2 );
You need to change the
100
to match the ID of the Block Element you want to disable.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 1, 2022 at 4:06 am #2330353Tobias
Hi David,
That code works like a charm!
Thanks 🙂
September 1, 2022 at 4:31 am #2330370David
StaffCustomer SupportGlad to hear that
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.