Skip to content

Hide Weak Tags (code snippet)

This WordPress code snippet helps to hide tags with less than 10 posts. Because you do not want to show “tag page” if it has only 1 or 2 posts.

On not optimized blogs such weak tags can count for up to 80% of all tags.

Watch tutorial on YouTube.

Code snippet

/* https://veppa.com/hide-weak-tags/ version:1.0 */

/* hide tags with count less than "x" posts */
add_filter('get_tags', 'veppa_hide_weak_tags', 10, 1);
add_filter('get_the_tags', 'veppa_hide_weak_tags', 10, 1);
add_filter('wp_generate_tag_cloud_data', 'veppa_hide_weak_tags', 10, 1);

function veppa_hide_weak_tags($tags){
	// set your own treshold 
	$minimum_count = 10;

	if(!empty($tags) && is_array($tags)){
		$return = array();
		foreach($tags as $tag){ 
			$count = !empty($tag->count) ? $tag->count : (!empty($tag['real_count']) ? $tag['real_count'] : 0);

			if($count >= $minimum_count) {
				$return[]=$tag;
			} 
		}
		$tags = !empty($return)? $return : false; 
	}
	return $tags;
}

Benefits:

  • Reduce duplicate pages. Do not link to pages with very little information.
  • Reduce SEO crawl budget for your website. Generally in a blog with 100 tags and 100 posts, only 20-30 will be visible after hiding weak tags.
  • Prevent diluting internal link power (used in SEO).

Features:

  • Removes tags with few posts from tag cloud and inside post.
  • Tags with less than 10 posts are not visible until they reach to 10.
  • You can define your own threshold. Default is 10 posts.

Before / After hiding weak tags

Before / After comparison of tag cloud in a blog.

This screenshot shows before / after optimization using this code snippet. As you can see tags with less than 10 posts hidden from the tag cloud in WordPress.

What happens when tag is hidden using this snippet?

  • Tag will not be visible on front pages: post page. and tag cloud.
  • Tag page (page listing posts related to given tag) will continue functioning as normal but without other pages automatically linking to it. It will return 200 status code as a regular page.
  • When tag reaches threshold it will be visible again as other tags. If it goes below threshold then tag will be hidden.
  • Tag will operate regularly in the admin area. You can add, edit, delete those tags, add them to posts without problem.

FAQ

What are weak tags?

Weak tags in WordPress. Tags with few (less than 10) posts.

Weak tags are tags with few posts.

Every tag has a separate page that lists posts related to that tag. When tag has few posts then that listing page will not be much useful.

Mostly you would want to show pages with more than 10 posts.

You can change this number and set your own threshold $minimum_count = 10; in the current code snippet.

Can I remove tags all together?

Yes, for small blogs with less than 1000 posts you can delete all tags and use only categories. This will be much cleaner approach for organizing your blog content.

Remove tags using default WordPress admin area. Which is located in the “Posts” → “Tags” page.

For bigger blogs with more than 1000 posts and growing you may want to use tags. Tags will help to niche down and cross reference posts further. They can also help to display related posts.

If you decide to use tags then use no more than 5 tags per post and try to use general tags that can not be used as a category.

Using tags is totally up to you. Main goal is not to convert your blog to link mess.

How this will help with SEO?

Organizing your website by removing pages containing little information will help to reduce number of low quality pages. This will increase portion of helpful pages.

Not helpful and duplicate pages wastes users’ time. What is not useful for user not valued by search engines as well.

What is next:

Leave a Reply

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