This post explains how to add a Tags field to any USP Pro Form.

General Usage

Here is the shortcode that displays the Tags field:

[usp_tags]
Important! The [usp_tags] shortcode can be used only once per form.

You can add that directly to any USP Pro Form to display the Tags field, where users can enter tags along with their submitted post. By default, no tags will be included in your tags field. To include some tags, follow these steps:

  1. Visit plugin General settings ▸ Tag Settings
  2. For the option “Tag Menu”, select either Dropdown or Checkboxes
  3. Scroll down a bit to the option “Post Tags”, and click the “Show/Hide Tags” link to toggle open a list of your available tags
  4. Select any tags that should be displayed by default in any form (globally)

After saving your changes, any selected tags will be displayed in any USP Form that includes the [usp_tags] shortcode. To set which tags are displayed for any specific form, you can use shortcode attributes. Here are some quick examples:

// include tags selected in step 4 above (default)
[usp_tags]

// include tags with IDs 10, 11, 12
[usp_tags include="10,11,12"]

// include all non-empty tags
[usp_tags include="all"]

// include all tags even if empty
[usp_tags include="all_include_empty"]

Lots of other attributes are available for the [usp_tags] shortcode, so you can customize the Tags field as needed for each of your different forms. Note that [usp_tags] may be used only once per form.

Quicktags! When you are building a form on the “Edit USP Form” screen, you will find several rows of Quicktag buttons that can be used to easily add various field shortcodes (like Post Title, Name, Email, etc.). To add the Tags shortcode, click on the “USP:Tags” Quicktag. That will give you a popup box where you can choose your options and add to the form.

The next sections below provide some examples of how to customize the tags field on any form using its various shortcode attributes.

Add Tags to Individual Forms

To override the default/global tags for any specific form. Add the include attribute to the tags shortcode, like so:

[usp_tags include="10,11,12"]

Any tags specified via include will be displayed, along with any that are specified globally. Note that you can use include="all" to display all non-empty tags, or include="all_include_empty" to display all tags, even if empty.

Exclude Tags on Individual Forms

To exclude any default/global tags from displaying. Add the exclude attribute to the tags shortcode, like so:

[usp_tags exclude="10,11,12"]

Check out the shortcode documentation for details.

Allow Users to Add New Tags

You also can enable users to specify their own tags using the text-input field.

Allow numbers as tag names

When using the text-input field via the [usp_tags type="input"] shortcode, you can allow numbers as the tag name by adding this code snippet to your theme’s (or child theme’s) functions.php file:

// USP Pro - Allow numbers as tag names
function usp_post_tags_use_id($use_id) { return false; }
add_filter('usp_post_tags_use_id', 'usp_post_tags_use_id');

By default, the text tags field uses numbers as tag IDs, which makes it impossible for users to add numerical tags like 1, 2, or any number. Adding the above code snippet tells USP Pro to not treat numbers as IDs.

Assign Specific Tags to All Forms

Another way of adding tags is to automatically assign tags via hidden field. There are two ways of doing this, globally or locally.

Globally

To set required tags that will be assigned to all USP Forms. Visit USP Pro General Settings ▸ Tag Settings, and enable the setting, “Hide Tags Field”. With this setting enabled, the tags field that is displayed via the tags shortcode [usp_tags] will be hidden. This enables you to configure the field using attributes like include and exclude to fine-tune which tags are included automatically.

Locally

To set required tags locally (on a per-form basis), add the tags attribute to the tags shortcode, for example:

[usp_tags tags="1,2"]

This shortcode will display the tags field along with a hidden field that auto-assigns the tags 1 and 2 to any posts submitted via the form. Note that we’re using tag IDs for all shortcode attributes.

Where do I find my tag IDs? There are a couple of ways. First you can visit Posts ▸ Tags, and then long-hover your cursor over any tag link. In most browsers, doing this will reveal the full URL at the bottom of the browser window (or somewhere). In the URL, you will see an ID with a number — that is the tag ID. Alternately, you can get tag IDs directly in the USP Pro General settings. Visit the Tag Settings, toggle open the “Post Tags” list, and hover your cursor over any tag link. The associated tag ID will be displayed in the resulting tooltip info.

Related