How to Create a Smart Tag for the Entry ID

Introduction

Would you like to create a Smart Tag for the Entry ID number from your form entries? You can easily create a tag that will allow you to capture the entry ID number and add it to your Confirmation Message once the form is submitted. You can also even add this to your form notifications. In this tutorial, we’re going to show you exactly how to achieve this.

Registering the Smart Tag

To begin, we’re going to add the following snippets to our site that will capture the WPForms Entry ID that is assigned automatically with each new form submission so that we can include this number inside the Confirmation Message but we will also add this to our email notification that the user will receive after submitting the form.

If you need any assistance in adding a snippet to your site, please see this tutorial.

/**
 * Register the Entry ID Smart Tag so it will be available to select in the form builder.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-the-entry-id/
 */
function wpf_dev_register_smarttag( $tags ) {
 
    // Key is the tag, item is the tag name.
    $tags['my_entry_id'] = 'Entry ID Number';
 
    return $tags;
}
add_filter( 'wpforms_smart_tags', 'wpf_dev_register_smarttag' );

Once the above snippet is added, you’ll notice that inside the form builder there is a new Smart Tag you can use labeled Entry ID Number.

once the first snippet is added, a new smart tag will appear called Entry ID Number

Anytime we now want to use this Smart Tag we would just {my_entry_id} for the Confirmations and Notifications tab of the form builder.

Assigning the Smart Tag

Once the Smart Tag has been registered, we now need to define what this tag is by assigning it to a value. In this particular instance we’re going to tell the Smart Tag whenever Entry ID Number is called for inside WPForms to look up the entry and assign the entry ID number value to this tag.

/**
 * Process the Entry ID Smart Tag.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-the-entry-id/
 */
function wpf_dev_custom_smarttags( $content, $tag ) {
   if ( $tag === 'my_entry_id' ) {
      $content = str_replace( '{' . $tag . '}', absint( wpforms()->process->entry_id ), $content );
   }
   return $content;
};
add_filter( 'wpforms_smart_tag_process', 'wpf_dev_custom_smarttags', 10, 2 );

Please note that the entry ID isn’t created until after the Submit button is clicked. Therefore using this for email notifications or confirmation messages is the only solution for this Smart Tag.

For this example, we’re going to add the Smart Tag on the Confirmations for the confirmation message. From the form builder settings, click on the Confirmations tab and add your message with the Smart Tag included.

just add the smart tag to the confirmation message on the Confirmations tab

Next, we’re going to add the Smart Tag to the email notifications. Click on the Notifications tab and add the message you want to appear inside the Email Message.

Add the smart tag to the email message on the Notifications tab

Now, when a form is submitted, the user will see the entry ID inside their confirmation message and in their copy of the email notification.

By adding the smart tag to the confirmation message

And that’s it! You’ve successfully created a new custom Smart Tag for the Entry ID number that can be used in several places in your form. Would you like to create a custom Smart Tag for the current time as well? Take a look at our tutorial on How to Create a Smart Tag for the Current Time.

Filter References: