WordPress – How To Limit Number of Tags In Tag Cloud

In WordPress tag cloud has become an integral part and it is my favorite too. It tops up category and provides visitors a view on the popular keywords.

In this article I’ll describe how to limit number of tags in WordPress.

Basically there are various way to limit number of tags in tag cloud.

Method – 1: Changethe limit in the core file

This is the simplest way to change the number of tags to show in tag cloud.

Open /wp-includes/category-template.php file and search for following function:
[sourcecode language=”php”]function wp_tag_cloud( $args = ” ) {
$defaults = array(
‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,
‘format’ => ‘flat’, ‘separator’ => "\n", ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,
‘exclude’ => ”, ‘include’ => ”, ‘link’ => ‘view’, ‘taxonomy’ => ‘post_tag’, ‘echo’ => true
);
[/sourcecode]
See ‘number’ => 45
45 is the default number of tags which shows up in the tag cloud in WordPress. Change 45 to whatever you like. I normally use 25-30.

However there is a problem with this method. When you upgrade WordPress your changes will be lost and you have to do again. If you manage hundreds of blog like me then it will nightmare to do these changes over and over again.

So this method is not recommended.

Method – 2: Use Configurable Tag Cloud (CTC) plugin

This is one of my favorite plugin which I almost use in all of my blogs.

Install Configurable Tag Cloud (CTC) plugin and in Widget change the number of tags you want to show in tag cloud.

CTC Settings
CTC Settings

CTC plugin works fine for me however for one reason that I have to desert this plugin. I’ve to use a hook to make all tags in tag cloud to have rel=”nofollow” attribute. This hook doesn’t work for CTC plugin.

Method 3 – Use wp_tag_cloud function

This is the best method to limit the number of tags in tag cloud and keep all the default features of tag cloud.

Use WordPress function wp_tag_cloud and pass the number parameter to it.
See the code below:

[sourcecode language=”php”]
<?php if ( function_exists(‘wp_tag_cloud’) ) : ?>
<li>
<ul>
<?php wp_tag_cloud(‘number=30’); ?>
</ul>
</li>
<?php endif; ?>
[/sourcecode]

You can copy above code and paste in theme file, usually sidebar.php where you want to show the tag cloud.

You can also use PHP Code Widget plugin and add above code in the PHP Code Widget. See below

Add Custom Tag Cloud Code into PHP Code Widget
Add Custom Tag Cloud Code into PHP Code Widget

You can see this implementation live on Movies blog. See the 3rd Footer widget.


Comments

Leave a Reply

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