There is a lot of information on this topic online that helps you customize your WordPress tag. Generally, you may be advised to do this by editing the WordPress core files, but this way can lead to errors later in your blogging for you might be faced with the challenge of retracing your steps the next time you need to update something.
It takes cautions to achieve the desired results without compromising the state of the blog. Therefore, in the following, we have come out a related tutorial about how to customize the WordPress tag cloud widget, leaving the core files of your WordPress sites untouched.
What is WordPress Tag Cloud Widget?
This is one of the widgets that have been on WordPress for a long time, giving brief details on what your blog is all about. It is a widget that you should have on your site or blog mostly if you use tags when publishing.
WordPress Tag Cloud Widget is specially clicked by your readers, connecting them to the older posts on your blog. Besides, as this widget is an in-built function on WordPress that gives tag clouds automatically, it makes things easy to create tag clouds using categories, tags and custom taxonomies.
Customize the Standard Tag Cloud Widget on WordPress
Customize the built-in WordPress tag cloud function is a little bit complex, sometimes a challenge to bloggers. There is an array of plugins that give numerous customizing options, but the most important functions needed excludes modifying tags, changing font sizes and changing cloud formats. Therefore, you need to use some lines of code to achieve your goal. The detailed steps and coding stuff are listed in the following.
You need to dig deeply in the core files to understand their functions, so that you can have the enough knowledge to customize the tag cloud widget with ease. These learning things can be found on the WordPress Codex Directory.
After gaining the needed knowledge and examining how files are named among other things, you now can look for a file called as widgets.php. This is a file with the standard widgets on WordPress. Open this file, click on wp widget tag cloud and spot the codes presented in below.
You can then use the widget_tag_cloud_args and utilize the core as the taxonomy.
Once you are done with the cores, close the window and ensure that no changes are saved. Saving the changes results in editing of the core files that may bring issues later.
You now need to add a filter in your plugin to identify the handler function. This simply results in something like as below.
Ensure that all passed arguments are returned and remember that there is an instance that you need to edit $args. This is the variable you pass on the wp_tag_cloud.
Change the Total Number of Tags to Display
Number key determines the highest number of tags at once. The default number is 45, but you can reduce that up to 20. After the steps above, you can have your handler function looking like this if you want to make it 20 or so.
This practice is simple, and its results are immediate unless you do not have tags on your blog.
Chang Font Sizes between Smallest and Largest
Now, you can also change the smallest and the largest font sizes without editing the core files. You may have units, for instance, featuring the 22 pixels for the largest and 11 pixels for the smallest. After this, the handler function can look like this.
Note that the above lines of code include the earlier set number of tags to display, and you can modify the number as you wish.
Exclude a Tag from the Cloud
The “include” and the “exclude” keys reject strings as they work with IDs terms. You may find it simple to find an ID for specific terms through your admin panel. After you find the terms, click on one of them to edit.
Now, you can note your term ID on the URL of your browser in the form of a tag ID. Select the term IDs you want to exclude and proceed as follows; for instance, you want to exclude ID 30 and ID 70.