tags - Primary Taxonomy for Post

admin2025-01-07  5

My blog posts have have multiple items from my custom taxonomy attached to them. For the sake of this post lets just use Tags taxonomy...

So a post may contain 4 tags, is there a way I can select one tag as the primary tag for the post?

My blog posts have have multiple items from my custom taxonomy attached to them. For the sake of this post lets just use Tags taxonomy...

So a post may contain 4 tags, is there a way I can select one tag as the primary tag for the post?

Share Improve this question asked Jun 21, 2014 at 23:13 ImranImran 2235 silver badges12 bronze badges 1
  • I think you can create a custom field primary tag and little script. Custom Field is select box all tags used for this post and script to update sync data of Tags with select box on tags field update – Dat Nguyen Commented May 31, 2017 at 2:41
Add a comment  | 

2 Answers 2

Reset to default 0

This post is super old but I'll post my solution here in case anyone else stumbles across this.

If you're using Yoast SEO you can hook into their existing implementation (they do this already for categories).

function add_variety_primary_term_taxonomy( $taxonomies, $post_type, $all ) {
    if( $post_type == 'product' && isset( $all['my_custom_tax'] ) ) {
        $taxonomies['my_custom_tax'] = $all['my_custom_tax'];
    }

    return $taxonomies;
}

add_filter( 'wpseo_primary_term_taxonomies', 'add_variety_primary_term_taxonomy', 10, 3 );

Also, your custom taxonomy must have 'hierarchical' => true for this to work.

Good luck!

No, you cannot. Taxonomies, categories, and terms all carries the same rank in the hierarchy when they are at the same level. If you attach a post to 4 taxonomies, categories, or terms on the same level, all these taxonomies will be equal in rank.

The only way you can achieve what you are trying to do, is to create a parent with a few children under that parent, attach the post to the parent and a couple of children. That parent will then be the "primary" tag for the post

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254904a242.html

最新回复(0)