Mixing Business with Pleasure since 1999

Custom WPForms Smart Tags with Arguments

Reading Time: < 1 minute

The WPForms plugin is my new favorite form plugin. It’s very clean and super easy to use. However since it’s still relatively new in the game there are some things that you might have to do manually/the hard way.

For instance they have their own smart tags system to build up emails and notifications. Sorta like shortcodes but not that advanced. Right now if you wanted to create your own smart tags you can do that, but there isn’t any documented way to add parameters to them unless you want to dive in to the code … Until now.

Say you wanted your smart tag to trigger some specific event function upon form completion and that code required an argument?

You can use the following filter and preg_match to find the smart tag and value:

 * Custom WPForms Smart Tag with argument.
 * @link https://jonkristian.no/2018/02/custom-wpforms-smart-tags-arguments/

function wpforms_custom_smart_tags( $content, $tag )
    // Check if there's a "tracking_event" tag.
    preg_match( "/\{tracking_event="(.+?)"\}/", $content, $event );
    if( !empty( $event[1] ) )
        // Fire our tracking event function.

        $value = ''; // We don't want to output anything.
        $content = str_replace( '{fbtrack_event="'.$event[1].'"}', $value, $content );

    return $content;
add_filter( 'wpforms_smart_tag_process', 'wpforms_custom_smart_tags', 10, 2 );

Hopefully WPForms will develop better ways to do this in the future, but for now we can use filters.

I know you could probably override the editor in wpforms to allow shortcodes but for security measures I believe this is the better option.


  1. Steve Maas

    Is there a way to create a “Insert Custom Field” ” Smart Tag in WPForms

    Example: Insert Custom Field Smart Tag


    – where ContactEmail and ContactName are custom fields for current post

    Having this Smart Tag for instance would allow me to create a single WPForm and place it on a contact page template. I could then use {Insert_Custom_Field=”ContactEmail”} as the email address in the WPForms > Admin Notification > Send to Email Address. This way when a customer finds a contact that he or she is interested in they could fill out the form and the form would route to the contact.

    Giving the option to specify the custom field name for the post would give tremendous flexibility

    • Jon Kristian

      That’s a clever idea! However I’m not sure how to go about it. At best you’d have to search the code and see where you need to override the send process, it should be possible. Take a look at Bill Erickson’s blog, he has some more code examples.

  2. Tim

    Hey. Do you think there is a way to filter just the fields which are filled in the specific forms?

    • Jon Kristian

      Hi Tim.

      Not entirely sure I understand what you want to do. Can you explain a bit more?

      If you just want to get the field values on/after submit you can use wpforms_process as explained here.

Leave a Reply to Steve Maas Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022 Jon Kristian

Theme by Anders NorenUp ↑