Display Popular Tags in WordPress

Display Popular Tags in WordPress
20017 Views
5
(1)

you’ll need to add following code to your current themes functions.php file.

<?php
function cxc_tag_cloud() { 
	$tags = get_tags();
   if( $tags ){
        foreach ( $tags as $tag ) {
            $tag_link = get_tag_link( $tag->term_id );
            $tag->link = $tag_link;
        }    
   }
	$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( 'cxc_popular_tags', 'cxc_tag_cloud' ); 

// Enable shortcode execution in text widget
add_filter( 'widget_text', 'do_shortcode' );
?>

This code simply generates the top 10 tags from your website in a cloud with number of posts in each tag. After that it creates a shortcode cxc_popular_tags and enables shortcode in text widget.

You can now add shortcode [cxc_popular_tags] in any post, page, or widget to display your most popular tags.

In WordPress, how can I make tags visible?

Add the ‘Tag Cloud’ widget to the sidebar by going to Appearance ยป Widgets. The widget will expand, allowing you to view its options.

How can I include popular posts in WordPress?

Open the editor on any page or post. Then, in the upper left corner, click the + symbol and pick the Popular Posts or Shortcode blocks.

How can I display popular posts?

Please check this tutorial. Click here

How useful was this blog?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this blog.

12 comments

  1. Excellent way of describing, and a good article to obtain information concerning my presentation subject matter, which I am going to deliver in university.

Leave a comment

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