### [How to Create a Smart Tag Site URL](https://wpforms.com/developers/how-to-create-a-smart-tag-site-url/)

**Published:** April 21, 2023
**Author:** David Ozokoye

**Excerpt:** This tutorial will show you how to create a Smart Tag Site URL so that you can re-use this without having to type out your URL for each form. 

**Content:**

## Introduction

Would you like to create a Smart Tag Site URL? Perhaps you’d like to re-use this Smart Tag in your email notifications or confirmation messages? In this tutorial, we’ll show you how you can create a Smart Tag for your site URL but also how and where to place it inside your notifications.

## Adding the Snippet

To begin, we’re going to add our snippet to the site first. If you need any help with how and where to add snippets, [please be sure to review this helpful documentation](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

```

/**
 * Process the Smart Tag.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-site-url/
 */

function wpf_dev_register_site_smarttag( $tags ) {

    // Key is the tag, item is the tag name.
    $tags[ 'site_url' ] = 'Site URL';

    return $tags;
}
add_filter( 'wpforms_smart_tags', 'wpf_dev_register_site_smarttag', 10, 1 );

/**
 * Process the Smart Tag.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-site-url/
 */

function wpf_dev_process_site_url_smarttag( $content, $tag ) {

    // Only run if it is our desired tag.
    if ( 'site_url' === $tag ) {

        // Assign the site URL to the $url variable
        $url = get_site_url();

        // Replace the tag with our link.
        $content = str_replace( '{site_url}', $url, $content );

    }

    return $content;
}
add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_site_url_smarttag', 10, 2 );
```

This snippet has two functions. The first is just registering that we’re going to create a Smart Tag called **site\_url** however, the text we’ll see inside the form builder for this particular Smart Tag is **Site URL**.

The second function will look for the current site URL with the WordPress function **get\_site\_url();** and then we’ll pass that inside the function and assign the **$url** variable inside the Smart Tag.

## Using the Smart Tag

For the purpose of this documentation, we’re placing a thank you image inside each email notification that our visitors receive after completing our form. To do this, we’ll head to the Notifications tab and add this after the **{all\_fields}** Smart tag in our notification message.

Just add your HTML link and image source to your **Email Message** on your **Notifications** tab.

```

```

![use the new smart tag to add an image](https://wpforms.com/wp-content/uploads/2023/04/wpforms-domain-url-smart-tag.jpg)And that’s it! There is so much you can do with Smart Tags in WPForms. Check out our tutorial on [How to Create a Custom Smart Tag](https://wpforms.com/developers/how-to-create-a-custom-smart-tag/ "How to Create a Custom Smart Tag") to start creating your own custom Smart Tags.

## FAQ

#### Q: What if I wanted to use this inside an HTML form field or Label?

**A:** Smart Tags can be used in many areas by default such as confirmation messages, email notifications, **Default Value** for certain form fields. However, if you wanted to use Smart Tags inside field labels or in an HTML form field, there will be an extra snippet you may need to add.

```

```

![create a smart tag site URL with this snippet](https://wpforms.com/wp-content/uploads/2023/04/wpforms-smart-tag-domain-url.jpg)For further information on the snippet needed to process Smart Tags inside an HTML form field, [please review this tutorial](https://wpforms.com/developers/how-to-process-smart-tags-in-html-fields/ "How to Process Smart Tags in HTML Fields").

If you’d like to process Smart Tags inside a field label, [be sure to check out this tutorial](https://wpforms.com/developers/how-to-process-smart-tags-in-field-labels/ "How to Process Smart Tags in Field Labels").

Did you know that you can also use Smart Tags as options for your **Checkbox** field? You can see that tutorial by [reading this documentation](https://wpforms.com/developers/process-smart-tags-in-checkbox-labels/ "How to Process Smart Tags in Checkbox Labels").

#### Q: Is it possible to truncate the URL?

**A:** Absolutely! If you want to use the permalink of the current post or page to populate a field, you can utilize this snippet instead.

```

/**
 * Process the Smart Tag.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-site-url/
 */

function wpf_dev_register_site_smarttag( $tags ) {

    // Key is the tag, item is the tag name.
    $tags[ 'permalink' ] = 'Permalink';

    return $tags;
}
add_filter( 'wpforms_smart_tags', 'wpf_dev_register_site_smarttag', 10, 1 );

/**
 * Process the Smart Tag.
 *
 * @link   https://wpforms.com/developers/how-to-create-a-smart-tag-for-site-url/
 */

function wpf_dev_process_site_url_smarttag( $content, $tag ) {

    // Only run if it is our desired tag.
    if ( 'permalink' === $tag ) {

        // Assign the site URL to the $url variable
	$url = substr( get_permalink(), strlen( home_url('/') ) );

        // Replace the tag with our link.
        $content = str_replace( '{permalink}', $url, $content );

    }

    return $content;
}
add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_site_url_smarttag', 10, 2 );
```

## Related

Filter References:

- [wpforms\_smart\_tags](https://wpforms.com/developers/wpforms_smart_tags/ "Using the wpforms_smart_tags filter")
- [wpforms\_smart\_tag\_process](https://wpforms.com/developers/wpforms_smart_tag_process/ "Using the wpforms_smart_tag_process filter")

**Categories:** Tutorials

**Tags:** PHP, Smart Tag

---

