WordPress, Possible to have the Tag Cloud Widget only display tags assigned to the given post?

635 views Asked by At

I have included the tag cloud widget as an element within my blog posts. Is it possible to have the tag cloud only display relevant tags/tags assigned to the given post?

Thanks!

2

There are 2 answers

1
Luis Izquierdo On

Instead of using the tag cloud widget, I would recommend editing your single.php (prefereably in a child theme) to include post tags meta. You can use something similar to this:

function tags_after_single_post_content($content) {

if( is_singular('post') && is_main_query() ) {

$tags = the_tags('<div class="entry-meta">Tagged with: ',' • ','</div><br />'); 

$content .= $content . $tags;
    }
return $content;
}
add_filter( 'the_content', 'tags_after_single_post_content' );

It may differ depending on your theme.

0
Shan404 On

You can create and use a Shortcode

function my_tags_shortcode( $atts ) {
    global $product;
    echo wc_get_product_tag_list( $product->get_id(), ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '</span>' );
}
add_shortcode( 'my_tags_shortcode', 'my_tags_shortcode');

Then you can use the shorcode [my_tags_shortcode] anywhere in posts or pages.