Published on Jul 16, 2025 5 min read

How to Limit the Number of Tags in WordPress Posts

Users may quickly find similar content thanks to WordPress tags, which also help keep your site organized. However, using too many tags can be counterproductive. It can affect your site’s performance, confuse visitors, and even impact your SEO. That’s why restricting the number of tags per post is crucial.

Regrettably, WordPress doesn’t include native tools for setting tag restrictions. Still, you can address this with a few simple actions. Whether you prefer a code snippet, a plugin, or a script, there’s a solution tailored to your needs. This guide will show you how to safely and easily limit the number of tags in WordPress posts.

A screenshot of WordPress tags dashboard

Why Limit the Number of Tags in WordPress?

Tags help users find related content easily and improve site structure and SEO. However, using too many can have the opposite effect.

Here are some reasons to limit tags:

  • Better readability: Excessive use of tags can overwhelm readers.
  • Improved SEO: Search engines may view tag-stuffed posts as spammy.
  • Site speed: Fewer tags mean less processing for WordPress and plugins.
  • Content quality: It forces writers to choose more relevant tags.

Most experts recommend using no more than 5–10 tags per post.

WordPress tags setup

Option 1: Use a Simple Code Snippet in functions.php

If you’re comfortable editing your theme’s files, try this method.

Step 1: Open Your Theme Folder

Go to your WordPress dashboard. From the left menu, click on “Appearance” and then “Theme File Editor.”

Step 2: Edit the functions.php File

Find and click on functions.php. Scroll to the bottom of the file.

Step 3: Add This Code Snippet

function limit_post_tags($post_ID) {
    $post_tags = wp_get_post_tags($post_ID);
    $max_tags = 5; // Set your tag limit here
    if (count($post_tags) > $max_tags) {
        $tags_to_keep = array_slice($post_tags, 0, $max_tags);
        $tag_ids = wp_list_pluck($tags_to_keep, 'term_id');
        wp_set_post_tags($post_ID, $tag_ids);
    }
}
add_action('save_post', 'limit_post_tags');

This snippet checks the number of tags used in a post. If it’s more than 5, it removes the extra tags.

Option 2: Use a Custom Plugin (No Coding Required)

If you prefer not to edit theme files, create a simple plugin.

Step 1: Go to the Plugins Folder

Use FTP or File Manager in your hosting panel. Navigate to wp-content/plugins/.

Step 2: Create a New File

Name it something like limit-tags.php.

Step 3: Paste This Plugin Code

<?php
/*
Plugin Name: Limit Post Tags
Description: Limit the number of tags for WordPress posts.
Version: 1.0
*/

function limit_post_tags_plugin($post_ID) {
    $max_tags = 5;
    $post_tags = wp_get_post_tags($post_ID);
    if (count($post_tags) > $max_tags) {
        $tags_to_keep = array_slice($post_tags, 0, $max_tags);
        $tag_ids = wp_list_pluck($tags_to_keep, 'term_id');
        wp_set_post_tags($post_ID, $tag_ids);
    }
}
add_action('save_post', 'limit_post_tags_plugin');

Step 4: Activate the Plugin

Go to your WordPress dashboard. Click on “Plugins,” find “Limit Post Tags,” and click “Activate.”

Option 3: Use a Plugin Like “Advanced Custom Fields” (ACF)

If you’re already using ACF, this method will work well.

Step 1: Install and Activate ACF

Go to Plugins > Add New and search for Advanced Custom Fields. Install and activate it.

Step 2: Create a New Field Group

Go to Custom Fields > Add New.

Step 3: Add a “Tags” Field

Set the field type to “Taxonomy” and choose “Tags.” Under “Appearance,” set it to “Checkbox” or “Multi Select.”

Step 4: Set a Rule

Set location rules to show this field when editing posts.

Step 5: Limit the Selection

Unfortunately, ACF doesn’t limit selection by default. However, you can use JavaScript or an additional plugin, such as ACF Toolkit, to enforce limits.

Option 4: JavaScript Validation (Frontend Block)

You can also add a script that warns users when they select too many tags.

Step 1: Go to functions.php

Add the following code to load your script:

function limit_tags_script() {
    ?>
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        const tagInput = document.querySelector('#new-tag-post_tag');
        const tagList = document.querySelector('#post_tag .tagchecklist');

        function countTags() {
            let tags = tagList.querySelectorAll('span');
            if (tags.length >= 5) {
                alert("Maximum 5 tags allowed.");
                tagInput.disabled = true;
            } else {
                tagInput.disabled = false;
            }
        }

        tagList.addEventListener('DOMSubtreeModified', countTags);
    });
    </script>
    <?php
}
add_action('admin_footer', 'limit_tags_script');

This script monitors the tag input area. If tags reach 5, it disables the input.

Best Practices for Managing Tags

While setting a maximum number of tags helps, consider these additional tips:

  • Stay Consistent: Use consistent spelling for tags across all posts. Avoid creating duplicate tags by using the same format, either capitalizing every word or keeping them all lowercase.
  • Avoid Tag Stuffing: Don’t use excessive tags just to attract views. Using too many tags can make your content appear spammy and negatively impact SEO.
  • Use Relevant Tags: Only use tags that are directly related to your content. Consider whether a reader would find the tag useful.
  • Audit Your Tags Regularly: Review your tags every few months. Remove duplicates or tags used only once to keep your system organized.

Conclusion

Limiting the number of tags in WordPress posts is essential for organizing content effectively. It enhances the reader’s experience, aids in SEO, and streamlines your website. With the right guidance, using a code snippet, plugin, or JavaScript fix is straightforward. Remember to use correct tags and review them regularly. Organizing your tags not only helps readers navigate your site more easily but also improves the overall performance of your blog. Take control of your tags today and keep your WordPress site neat and well-organized.

Related Articles

Popular Articles