Support » Developing with WordPress » Custom CPT Archive Title

  • I’ve tried so many options but nothing really changes the title of this CPT https://drpraegers.com/recipe/

    Any suggestion?

        add_filter( 'get_the_archive_title', function ($title) {    
            if ( is_category() ) {    
                    $title = single_cat_title( '', false );    
                } elseif ( is_tag() ) {    
                    $title = single_tag_title( '', false );    
                } elseif ( is_author() ) {    
                    $title = '<span class="vcard">' . get_the_author() . '</span>' ;    
                } elseif ( is_tax() ) { //for custom post types
                    $title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
                } elseif (is_post_type_archive()) {
                    $title = post_type_archive_title( '', false );
                }
            return $title;    
        });
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @ayrancd,

    Have you tried to provide the CPT name to a is_post_type_archive() function, in this case it would be is_post_type_archive('recipe')?

    Thread Starter Cezar Ayran

    (@ayrancd)

    @igorradovanov I’ve tried the following code but for some reason it doesn’t change the title

        add_filter( 'get_the_archive_title', function ($title) {    
            if (is_post_type_archive('recipe')) {    
                    $title = "new title";    
                }
            return $title;    
        });

    Also tried

    add_filter('pre_get_document_title', 'change_taxonomy_title');
    function change_taxonomy_title($title) {
        if (is_post_type_archive('recipe')) {    
                    $title = "new title";    
                }
        return $title;
    }
    Moderator bcworkz

    (@bcworkz)

    Hi Cezar – the right solution really depends on how your theme handles archive titles.

    Anyway, looking at the link you provided, I don’t see any title that might be undesirable. Have you solved this? If so, when you get a chance, please mark this topic as resolved, thanks!

    Thread Starter Cezar Ayran

    (@ayrancd)

    @bcworkz what you mean title that might be undesirable? I’d like to change that title to Plant Based Recipes.

    Moderator bcworkz

    (@bcworkz)

    Ha! That title didn’t register as a title for me, I thought it was part of the image.

    As it now says “Plant Based Recipes” I’ll assume you figured out a solution and I’ll mark this topic as resolved. The topic remains open, you can still reply if that’s a bad assumption or you have further related questions.

    Thread Starter Cezar Ayran

    (@ayrancd)

    @bcworkz you got wrong.

    I don’t want to change the first section of that page “Plant Based Recipes” I want to change the <title> tag that says Recipes Archive

    Moderator bcworkz

    (@bcworkz)

    Oh! That title. Sorry for my confusion. “Resolved” tag removed, I’ll let you set it when it’s appropriate. It’s again theme dependent, but the filter hook you probably want is “wp_title”

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