Site logo

[Resolved] Archive Title and Description Display

Home Forums Support [Resolved] Archive Title and Description Display

Home Forums Support Archive Title and Description Display

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1892989
    Rachel

    Hi,
    I have created a block element to use as an Archive Page Hero as Leo explains in this youtube video – https://www.youtube.com/watch?v=L1KtrKJIFzk.

    I also have a code snippet to stop the category description displaying on the 2,3,4 pages, but with the new element it is displaying both the new element title and the standard WP category title on the subsequent pages.

    Can you let me know how to modify this snippet or the element so only the new element hero title is displayed on the subsequent pages?

    Thanks,
    Rachel

    Code Snippet:

    add_action( ‘wp’, ‘tu_remove_paged_category_description’ );
    function tu_remove_paged_category_description() {
    $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    if ( 1 !== $page ) {
    remove_action( ‘generate_archive_title’, ‘generate_archive_title’ );
    add_action( ‘generate_archive_title’, ‘tu_custom_paged_archive_title’ );
    }
    }

    function tu_custom_paged_archive_title() {
    ?>
    <header class=”page-header”>
    <h1 class=”page-title”>
    <?php the_archive_title(); ?>
    </h1>
    </header>
    <?php
    }

    #1893025
    Elvin
    Staff
    Customer Support

    Hi there,

    Can you try this PHP snippet?

    add_action( 'wp', 'tu_remove_paged_category_description' );
    function tu_remove_paged_category_description() {
    	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	if ( 1 !== $page ) {
    		remove_action( 'generate_archive_title', 'generate_archive_title' );
    		add_action( 'generate_archive_title', 'tu_custom_paged_archive_title' );
    	}
    }
    
    function tu_custom_paged_archive_title() {
    	$title = get_the_archive_title();
    	echo '<header class="page-header"><h1 class="page-title">'.$title.'</h1></header>';
    }

    If it doesn’t work, can you link us to the sample page in question?

    #1893083
    Rachel

    Hi Elvin,

    This doesn’t seem to have worked and the element title and description are still showing.

    I have added an example page below.

    Rachel

    #1894054
    Elvin
    Staff
    Customer Support

    Is this what you were trying to remove?

    If so, remove_action( 'generate_archive_title', 'generate_archive_title' ); won’t be able to remove that because that is added by a block element.

    You’ll have to filter this out using generate_block_element_display.

    Let us know if this is the case.

    #1894270
    Rachel

    Hi,

    I wanted to use the new block element to display the archive title and description on the first page of the archive, then just show the Block element Archive title on subsequent pages without the description.

    Previously with just the regular archive title I did this by way of a code snippet. I have removed the block element for now so if you take a look again, you will see what I mean.

    However when I add the block element in, the code snippet doesn’t work, and on the subsequent pages both the new block element header and the wordpress archive title are displaying.

    Is it possible to block the wordpress archive title from displaying on the subsequent pages, plus also block the block element description?

    Thanks,
    Rachel

    #1894355
    David
    Staff
    Customer Support

    Hi there,

    just so i understand correctly.
    On the Archive Page 1 – you want the Block Element to display the Title and Description.
    On the Paged archives ( page 2, 3 etc. ) – you only want the Block Element to display the Title

    Is that correct ?

    #1894499
    Rachel

    Hi David,

    Yes, that is correct..

    Thanks, Rachel

    #1896884
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Looking through the code – this doesn’t look possible right now, unfortunately. We need to add some more filters in the dynamic content block.

    Two options:

    1. Give the content a custom class and use CSS to hide it on paginated pages.
    2. Use a shortcode instead of the dynamic content block:

    add_shortcode( 'paged_dynamic_content', function() {
        if ( is_paged() ) {
            return;
        }
    
        return sprintf(
            '<div class="dynamic-term-description">%s</div>',
            term_description()
        );
    } );

    Let us know if you need more info 🙂

    #1898139
    Rachel

    Hi Tom, Thanks for looking into this. This looks a bit beyond my tech skills so I might just stick with the standard archive titles and description for now.

    Cheers, Rachel

    #1898249
    Tom
    Lead Developer
    Lead Developer

    We’ll see what we can do when it comes to a “if paginated” display condition 🙂

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