Site logo

[Resolved] Custom Archive Page Header

Home Forums Support [Resolved] Custom Archive Page Header

Home Forums Support Custom Archive Page Header

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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!

    #2246450
    Ying
    Staff
    Customer Support

    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?

    #2246606
    Lisa

    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.

    #2246637
    Fernando
    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.

    #2247751
    Lisa

    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!

    #2247762
    Ying
    Staff
    Customer Support

    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' );
    });
    #2248615
    Lisa

    Thank you so much! That did the trick.

    #2248646
    Ying
    Staff
    Customer Support

    You are welcome 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.