- This topic has 9 replies, 4 voices, and was last updated 4 years, 8 months ago by
Tom.
-
AuthorPosts
-
August 12, 2021 at 1:15 am #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,
RachelCode 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
}August 12, 2021 at 1:41 am #1893025Elvin
StaffCustomer SupportHi 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?
August 12, 2021 at 2:50 am #1893083Rachel
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
August 12, 2021 at 7:05 pm #1894054Elvin
StaffCustomer SupportIs 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.
August 13, 2021 at 1:32 am #1894270Rachel
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,
RachelAugust 13, 2021 at 3:36 am #1894355David
StaffCustomer SupportHi 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 TitleIs that correct ?
August 13, 2021 at 6:27 am #1894499Rachel
Hi David,
Yes, that is correct..
Thanks, Rachel
August 15, 2021 at 7:35 pm #1896884Tom
Lead DeveloperLead DeveloperHi 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 🙂
August 16, 2021 at 4:36 pm #1898139Rachel
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
August 16, 2021 at 8:48 pm #1898249Tom
Lead DeveloperLead DeveloperWe’ll see what we can do when it comes to a “if paginated” display condition 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.