Site logo

[Resolved] Change Custom Post Type Archive page when using Block Element for hero image

Home Forums Support [Resolved] Change Custom Post Type Archive page when using Block Element for hero image

Home Forums Support Change Custom Post Type Archive page when using Block Element for hero image

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

    #2455266
    Fernando
    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-title to 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-snippets

    Alternatively, you can just create a separate Page Hero just for that Archive page.

    #2461863
    Anastasiya

    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.

    Dynamic text

    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.)

    #2462099
    Ying
    Staff
    Customer Support

    Hi 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);
    #2462117
    Anastasiya

    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';
    #2463231
    Ying
    Staff
    Customer Support

    Oops, I’ve corrected my code 🙂

    Glad it works!

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