How to Create a Smart Tag for the Entry ID

Overview

Would you like to add the Entry ID number from your form submission to your Email Notifications or even the Confirmation Message? You can easily do this by creating a Smart Tag and assigning the Entry ID number. In this tutorial, we’ll give you the PHP code snippet necessary to achieve this.

Setup

First, you’ll need to copy and paste this code snippet to your site.

/**
 * 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/
 *
 * @param  array $tags
 *
 * @return array
 */
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' );


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

You can now use the Smart Tag {my_entry_id} anywhere that will accept a Default Value such as a Single Line Text form field or a Hidden Field form field, etc and it will show the message Your entry ID is and then the ID number.

For this example, we’re going to add the Smart Tag to the Confirmation Message and the Notification email.

You can now use the Entry ID Smart Tag inside the Confirmation Message

Now, when a form is submitted, the user will see the Entry ID inside their confirmation message.

The Entry ID Smart Tag now shows on the confirmation message

Entry ID Smart Tag

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: