I found this code (http://devotepress.com/faqs/display-popular-tags-wordpress) and I used the short code ([wpb_popular_tags]) but I do not see any result.
How can I use this code for displaying most popular WooCommerce product tags?
Here is their code:
function wpb_tag_cloud() {
$tags = get_tags();
$args = array(
'smallest' => 10,
'largest' => 22,
'unit' => 'px',
'number' => 10,
'format' => 'flat',
'separator' => " ",
'orderby' => 'count',
'order' => 'DESC',
'show_count' => 1,
'echo' => false
);
$tag_string = wp_generate_tag_cloud( $tags, $args );
return $tag_string;
}
// Add a shortcode so that we can use it in widgets, posts, and pages
add_shortcode('wpb_popular_tags', 'wpb_tag_cloud');
// Enable shortcode execution in text widget
add_filter ('widget_text', 'do_shortcode');
First, what do you have to know that you don't know may be:
Classic WordPress post tags are very different than WooCommerce "Product tags" which have a different custom taxonomy
'product_tag'
.So you cant use WordPress
get_tags()
to get the product tags.Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested in WooCommerce 3+ and perfectly works.