How to Display Most Popular Tags in WordPress

Do you want to display most popular tags on your WordPress website? Not to be confused, tags and categories are the two different default ways to sort your articles in WordPress. Categories often get more attention than tags due to their broader scope. Tags are well suited to specific ideas within the context of your articles.

Beginners often end up using these two aspects of WordPress incorrectly. But once you start using categories and tags correctly, you’ll likely have more tags than categories on your website.

By displaying most popular tags in WordPress, your users will shortly get a thought on what subjects are more regularly mentioned on your website. It will also assist them to uncover more content material, which means more page views and user engagement.

Now, let’s get back to our main topic, how you can easily display most popular tags in WordPress manually.

How to Display Most Popular Tags in WordPress Manually

Displaying the most popular tags in WordPress manually requires you to add code in your WordPress theme files.

You need to add the following code to your theme’s functions.php file.

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'); 

This code will simply generate the top 10 tags from your website in a cloud with a number of posts in each tag. After that, it creates a shortcode wpb_popular_tags and permits shortcode in the textual content widget.

You can now add the shortcode [wpb_popular_tags] in any post, page, or widget to show your most popular tags in WordPress.

display most popular tags in WordPress

That is it. Was it difficult? No, right? You just need to add codes and you will be able to display the most popular tags in WordPress. Now, go ahead and display the most popular tags on your website.

 

Reference: WP Beginner

Leave a Reply

Your email address will not be published. Required fields are marked *