WordPress Functions.php Customizing Topic Index

WordPress Functions.php Customizing Topic Index

Topic Index for "WordPress Functions.php Customizing"

Learn about customizing the WordPress functions.php in your theme.

How to Limit Tags in Tag Cloud Widget in WordPress

Have you ever tried to use the Tag Cloud widget in your WordPress but it appeared way too messy to use? Here at Top Five Advisor, we have over 100 tags that we have setup and we’re just getting started. Unfortunately, the default display of the tag cloud widget is to show all of your tags and increase in size depending on the tag use on your content.

WordPress Tag Cloud WidgetYou may notice that we have the following screenshot on the left displaying on the bottom of our website and you may be wondering how we did it.

Thankfully, all you need to do is make a quick edit in your functions.php file and you’ll be able to customize how many tags will appear in your widget area.

Simply change the number 5 on the “$args[‘number’] = 5;” line and the number you set will be the total tags allowed to be shown in that widget area, whether it is in your sidebar or footer areas.

Here’s the code snippet that you need to add to your functions.php:

// Limit Tags in Tag Cloud Widget
add_filter('widget_tag_cloud_args', 'tag_widget_limit');
function tag_widget_limit($args){
 if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
  $args['number'] = 5; // <-- Tags Limit
 }

 return $args;
}

What this will do is show your most popular tags in the tag cloud depending on the number you set. In our case, the screenshot in this post represents the 5 most popular tags as of the time of this posting.

How to Remove the URL Field in WordPress Comments

One of the greatest ways we’ve found to discourage spammers on our site is to remove the URL field in your WordPress comment section. Thankfully, this is a rather painless process that requires a small plugin or functions.php edit.

Option 1 – Functions.php Edit

Here’s the functions.php code snippet:

// Remove URL Field
add_filter('comment_form_default_fields', 't5a_remove_url');
function t5a_remove_url($fields) {
	if(isset($fields['url']))
	unset($fields['url']);
	return $fields;
}

Once you’ve added the following filter to your functions.php, you should notice that the URL field permanently disappears from your commenting area of all posts and pages that allow WordPress comments. This one is really awesome because your website will not even print the URL field in your posts and pages, blocking spambots from even attempting to submit comment spam.

Option 2 – WordPress Plugin

Although we attempt to limit our plugins whenever possible, we do realize that not everyone is comfortable with editing their functions.php or the child themes setup requires should you decide to update your theme to the latest version.

Install the Hide-n-Disable-comment-url-field plugin and you are off to the races.

In your dashboard, go to Plugins > Add New. In the search box, enter Hide-n-Disable-comment-url-field as your search query, then click search. From there, this plugin should be the first plugin in the list.

Install the plugin as usual, activate and you are done.

Time to Verify

To verify the changes are working, visit your WordPress website from a different web browser that is not currently logged in. Navigate to a post that is currently accepting comments and see if you have the website field.