Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Set Maximum Number of Tags for WordPress Posts

Do you want to limit the number of tags that your authors can add to your posts in WordPress?

Tags are a great way to organize your content, but a post with a lot of tags may not look good in your WordPress theme.

In this article, we’ll show you how to set a maximum number of tags for WordPress posts.

How to Set Maximum Number of Tags for WordPress Posts

Why Set a Maximum Number of Tags in WordPress?

Tags are a great way to organize your content, but beginners often make the mistake of adding dozens of tags in an attempt to improve their post’s SEO. This may not look very attractive with your WordPress theme.

While WordPress doesn’t place a limit on the number of tags that can be used, we recommend you normally stick to 10 tags maximum per post. This is best practice for improving your site’s SEO.

If you manage a multi-author blog or are training a new author on your site, then it’s helpful if you place a limit on the number tags allowed for each post.

With that being said, let’s look at how to set a maximum number of tags on your WordPress blog.

Setting a Maximum Number of Tags in WordPress

A simple way to add a limit to the number of tags that can be used on your WordPress website is by using a plugin like PublishPress Checklists.

PublishPress Checklists allow you to set tasks that authors must complete before publishing content. This includes setting limits on the number of categories and tags that can be applied to a post or page.

For this tutorial, you can use the free version of PublishPress Checklists, since it has the features we need. There’s also a premium version available that offers more features like checklists for WooCommerce products.

The first thing you need to do is install and activate the PublishPress Checklists plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you’ll need to go to Checklists on your WordPress dashboard. Next, you can set the maximum limit for the number of tags that can be used.

First, you can type the minimum and maximum number of tags that should be used in the Min and Max fields. For this tutorial, we’ll type 10 in the Max field and leave the Min field blank.

Type 10 in the Max Field

You will also need to change the ‘Disabled, Recommended or Required’ field from Disabled to either Recommended or Required

If you select Recommended, then authors can publish articles even if they go outside of the tag limit. However, the Required option makes it mandatory to stay within the tag count limits, so go ahead and select the Required option.

The PublishPress Checklists plugin also lets you exclude some user roles from meeting the word count requirement. For example, you might want administrators to be able to add additional tags when needed.

Simply click on the middle text box labeled ‘Who can ignore the task’ column and select a user role.

Exclude User Roles

When you’ve set the number of words writers should complete, simply scroll to the bottom of the page and click the ‘Save Changes’ button.

To see the tag limit in action, you should go to Posts » Add New to create a new blog post. Now add 11 tags to the post.

Tag Limit Preview

A warning icon will appear on the ‘Publish’ button in the WordPress editor. The plugin will also show that you have gone over the tag limit in the ‘Checklist’ settings box on your right.

Once your content meets the tag count limit, the checklist task will show a green checkmark, and the author can publish the blog post.

Displaying a Maximum Number of Tags in WordPress

Instead of placing a limit on the number of tags your authors can add to a post, you can simply display a limited number of tags on your WordPress site.

This method requires you to add a code snippet to your theme’s functions.php file. This is not suitable for beginners and could break your site. For more information, refer to our beginner’s guide on pasting snippets from the web into WordPress.

You’ll need to use an FTP client or your site’s theme editor to open your theme’s functions.php file.

Next, you should add this function by pasting it at the bottom of the file:

add_filter('term_links-post_tag','limit_to_five_tags');
function limit_to_five_tags($terms) {
return array_slice($terms,0,5,true);
}

This will display five tags with your post. To display a different number of posts, simply change the number 5 to the maximum tag count that you want.

Now check your website to check that only five tags are being shown. Here are before and after screenshots on our demo website.

Display Maximum Tags Preview

If your theme does not display any tags with your posts, then you need to add another code snippet.

You need to open the template where you want to display these post tags, such as loop.php, single.php, or index.php. Then you should paste the following code inside the loop:

<?php the_tags() ?>

A limited number of tags should now be displayed along with each post.

We hope this tutorial helped you learn how to set and display a maximum number of tags for WordPress posts.

You may also want to learn how to register and choose a domain name, or check out our list of the best managed WordPress hosting services.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

2 CommentsLeave a Reply

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.