Site logo

Archived topic

Custom Archive Page Header

7 replies · Started by Lisa on June 7, 2022

Viewing posts 1–8 of 8

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!

Hi Lisa,

1. To avoid duplicated title, make sure you toggle theDisable 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?

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.

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.

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!

That 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' );
});

Thank you so much! That did the trick.

You are welcome :)

This archived topic is closed to new replies.