Home › Forums › Support › Change Custom Post Type Archive page when using Block Element for hero image
- This topic has 5 replies, 3 voices, and was last updated 3 years, 4 months ago by
Ying.
-
AuthorPosts
-
December 8, 2022 at 12:56 pm #2455039
Anastasiya
Hi,
I am using Dynamic Data in Block element for custom post type archives page hero.
Custom post Type archive displays the name “Vimeo Videos” for the title element and I want to change it to something like :”All Videos”.
I tried using the following code but it has no effect on the title of the archive page:add_filter( 'get_the_archive_title', function( $title ) { if ( is_post_type_archive( 'vimeo-video' ) ) { $title = 'All Videos'; } return $title; }, 50 );My Question is: does the code above affect Dynamic data when creating page hero block element or not?
December 8, 2022 at 5:47 pm #2455266Fernando Customer Support
Hi Anastasiya,
You’ll need a different code if you’re working with a GB Headline Block on a Page Hero.
Try adding
change-titleto the class list of the Dynamic Headline Block, and then add this Snippet:add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'change-title' ) !== false && is_post_type_archive( 'vimeo-video' ) ) { return 'All Videos'; } return $content; }, 10, 3);Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippetsAlternatively, you can just create a separate Page Hero just for that Archive page.
December 14, 2022 at 9:27 am #2461863Anastasiya
Thanks Fernando,
I tried the code that you suggested but it had no effect on the output. The reason is probable because I didn’t explain myself correctly. I am using Dynamic text to output the archive title because Dynamic date toggle doesn’t output taxonomy archive titles.

Is there a filter that can be used for Dynamic text? I can’t find any of these filters in the list of official filters on the GP site.
(Note: I know that I can create a custom archive title but I am trying to limit the number of elements that are created on the website if possible.)
December 14, 2022 at 1:15 pm #2462099Ying
StaffCustomer SupportHi there,
Can you try the below snippet?
add_filter( 'render_block', function( $block_content, $block ) { if (! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'change-title' ) !== false && is_post_type_archive( 'vimeo-video' ) ) { $block_content = 'All Videos'; } return $block_content; }, 10, 3);December 14, 2022 at 1:40 pm #2462117Anastasiya
Thanks Ying, this code worked. there was small type in your answer (in case someone else will use the code):
&& strpos( $block['attrs']['className'], 'change-title' ) !== false && is_post_type_archive( 'vimeo-video' ) ) { $block_content = 'All Videos';December 15, 2022 at 10:59 am #2463231Ying
StaffCustomer SupportOops, I’ve corrected my code 🙂
Glad it works!
-
AuthorPosts
- You must be logged in to reply to this topic.