- This topic has 7 replies, 3 voices, and was last updated 3 years, 3 months ago by
Ying.
-
AuthorPosts
-
June 7, 2022 at 11:26 am #2246418
Lisa
I’m trying to use Elements to create a custom page header for archive pages. I’m trying to use a Dynamic tag to display the archive title. However, whenever I choose “Title” in the dynamic settings for the Element, the page header displays the title of the first article in the archive – not the archive page title. The archive page title displays below the new header. I’m setting the display conditions to archive.
I am creating this page header the same way I create page headers for pages and for the blog archive. I have it set as Page Hero, hook is after_header
I’m sure I’m missing something super simple, but not sure what it is.
Any help is appreciated.
Thanks!
June 7, 2022 at 12:09 pm #2246450Ying
StaffCustomer SupportHi Lisa,
1. To avoid duplicated title, make sure you toggle the
Disable title
option in your block element – page hero.2. Your setting should work for archive page, can you link us to an archive page where we can see the title added using block element?
June 7, 2022 at 5:11 pm #2246606Lisa
Thanks for the answer. I think I found part of the problem. It’s a conflict with SEOPress for the author archives. But it’s still not working for search results?
Here’s a link to a search results page. Password to view site is below:
https://edwardsstevens.sitedistrict.com/?s=advocate
Let me know if you need login access.
June 7, 2022 at 6:35 pm #2246637Fernando Customer Support
Hi Lisa,
If you would like to display the Search query as the title in the Search page, kindly
1. Add
hero-title
to the classes of the Headline Block for the title in your Block Element – Page Hero as such: https://share.getcloudapp.com/5zurJv6b
2. Then, add this code:add_filter( 'generate_dynamic_element_text', function( $text, $block ) { if ( is_search() && ! empty( $block['attrs']['className'] ) && 'hero-title' === $block['attrs']['className'] ) { $text = get_search_query(); } return $text; }, 10, 2 );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps! Kindly let us know how it goes.
June 8, 2022 at 4:09 pm #2247751Lisa
It worked half-way. I got the correct title in the Page Hero. But the title is still showing below in the content area, even though I have ticked “disable title” in the Element settings.
https://edwardsstevens.sitedistrict.com/?s=disability
Thanks for all your help. I’m going to save this snippet for future use!
June 8, 2022 at 4:35 pm #2247762Ying
StaffCustomer SupportThat option can’t remove the original search result title, try add this PHP snippet:
add_action('wp',function() { remove_action( 'generate_before_loop', 'generate_do_search_results_title' ); });
June 9, 2022 at 11:28 am #2248615Lisa
Thank you so much! That did the trick.
June 9, 2022 at 12:05 pm #2248646Ying
StaffCustomer SupportYou are welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.