[Resolved] Remove Prefix Before Title on CPT Archive Pages

Home Forums Support [Resolved] Remove Prefix Before Title on CPT Archive Pages

Home Forums Support Remove Prefix Before Title on CPT Archive Pages

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1437560
    Dean

    Hi Tom.

    I have created a CPT and also registered 2 custom taxonomies for it similar to how standard WP posts have categories and tags.

    However on the CPT taxonomy archives pages I am getting the name of the taxonomy displayed before the title. For example 1 of my taxonomies is “Series”. So on the archive page the main <h1> is displayed like this – Series: Example Series

    I searched the forum and found your following gist for those having a similar issue but with Archives in the title.

    https://gist.github.com/anonymous/06dbd945fa11991d7af1a8d6800f0f87

    However the above gist had no effect for me. I tried change priority and a few different things but couldn’t get it to work. Any idea where I am going wrong?

    #1437980
    David
    Staff
    Customer Support

    Hi there,

    can you share a link to an archive where i can see the issue?

    #1438047
    Dean

    Hi David.

    This is on localhost so I cannot share a link.

    However, I have found that this snippet has no affect whatsoever:

    add_filter( 'get_the_archive_title', 'tu_archive_title_remove_prefix' );
    function tu_archive_title_remove_prefix( $title ) {
        if ( is_post_type_archive() ) {
            $title = post_type_archive_title( '', false );
        }
    
        return $title;
    }

    But this snippet replaces the title with “Test” which is not the desired outcome but I think helps to highlight the issue:

    add_filter( 'get_the_archive_title', 'tu_archive_title_remove_prefix' );
    function tu_archive_title_remove_prefix( $title ) {
        /*if ( is_post_type_archive() ) {
            $title = post_type_archive_title( '', false );
        }*/
    
        $title = 'Test';
    
        return $title;
    }

    Here is the code I am using to create the custom taxonomy:

    function ls_register_series_taxonomy() {
        $labels = array(
          	'name'                       => _x( 'Series', 'Taxonomy General Name', 'my-books-cpt' ),
          	'singular_name'              => _x( 'Series', 'Taxonomy Singular Name', 'my-books-cpt' ),
          	'menu_name'                  => __( 'Series', 'my-books-cpt' ),
          	'all_items'                  => __( 'All Series', 'my-books-cpt' ),
          	'parent_item'                => __( 'Parent Series', 'my-books-cpt' ),
          	'parent_item_colon'          => __( 'Parent Series:', 'my-books-cpt' ),
          	'new_item_name'              => __( 'New Series Name', 'my-books-cpt' ),
          	'add_new_item'               => __( 'Add New Series', 'my-books-cpt' ),
          	'edit_item'                  => __( 'Edit Series', 'my-books-cpt' ),
          	'update_item'                => __( 'Update Series', 'my-books-cpt' ),
          	'view_item'                  => __( 'View Series', 'my-books-cpt' ),
          	'separate_items_with_commas' => __( 'Separate Series with commas', 'my-books-cpt' ),
          	'add_or_remove_items'        => __( 'Add or remove Series', 'my-books-cpt' ),
          	'choose_from_most_used'      => __( 'Choose from the most used', 'my-books-cpt' ),
          	'popular_items'              => __( 'Popular Series', 'my-books-cpt' ),
          	'search_items'               => __( 'Search Series', 'my-books-cpt' ),
          	'not_found'                  => __( 'Series Not Found', 'my-books-cpt' ),
          	'no_terms'                   => __( 'No Series', 'my-books-cpt' ),
          	'items_list'                 => __( 'Series list', 'my-books-cpt' ),
          	'items_list_navigation'      => __( 'Series list navigation', 'my-books-cpt' ),
        );
        $rewrite = array(
            'slug'                       => 'series',
            'with_front'                 => false,
            'hierarchical'               => true,
        );
        $args = array(
          	'labels'                     => $labels,
          	'hierarchical'               => true,
          	'public'                     => true,
          	'show_ui'                    => true,
          	'show_admin_column'          => true,
          	'show_in_nav_menus'          => true,
          	'show_tagcloud'              => true,
            'rewrite'                    => $rewrite,
            'show_in_rest'               => true,
        );
        register_taxonomy( 'series', array( 'books' ), $args );
    
    }
    add_action( 'init', 'ls_register_series_taxonomy');
    #1438578
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Since it’s a taxonomy archive, you could try this:

    add_filter( 'get_the_archive_title', function( $title ) {
        if ( is_tax() ) {
            $title = single_term_title( '', false );
        }
    
        return $title;
    } );
    #1438726
    Dean

    Thanks Tom. That did the trick. I didn’t realise there was a difference between archive and taxonomy archive. Thought they were all just classed as archives.

    Thanks again πŸ™‚

    #1438772
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #1558623
    Joshua

    Ahhh just what I was looking for! GeneratePress team is awesome, everytime I think I’m going to post a support topic, I do a quick search and find the answer 9 times out of 10. Thanks guys!

    #1559631
    Tom
    Lead Developer
    Lead Developer

    Awesome, great to hear! Thanks πŸ™‚

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