• Resolved klewis

    (@blackawxs)


    I have a 3 stage site that consists of dev, test and production branch. Each branch has their own URLs. I am using WP Forms on each of these branch sites. I have an image I am displaying a single image within the “notifications” area.

    So for example, I am putting in<img src="https.../my-image.jpg"> into the notification message box, so that users who open the notificaiton email see the image.

    My question is….is there a smart tag we can use in our notification area of WP Forms, that will give us the site root URL? So we can do something like this….

    <img src="{site_url}/my-image.jpg" width="100" height="100">

    • This topic was modified 1 year, 11 months ago by klewis.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @blackawxs – Thank you for your patience here!

    To achieve what you have mentioned, please add the below custom smart tag code to fetch the site’s root URL.

    function wpf_dev_register_smarttag( $tags ) {
    
        // Key is the tag, item is the tag name.
        $tags[ 'domain_url' ] = 'Domain URL';
    
        return $tags;
    }
    add_filter( 'wpforms_smart_tags', 'wpf_dev_register_smarttag', 10, 1 );
    
    /**
     * Process the Smart Tag.
     *
     * @link   https://wpforms.com/developers/how-to-create-a-custom-smart-tag/
     */
    
    function wpf_dev_process_smarttag( $content, $tag ) {
    
        // Only run if it is our desired tag.
        if ( 'domain_url' === $tag ) {
    
            // Replace our link in this demo with the URL you wish to provide
            $url = get_site_url();
    
            // Replace the tag with our link.
            $content = str_replace( '{domain_url}', $url, $content );
    
        }
    
        return $content;
    }
    add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_smarttag', 10, 2 );
    

    Next, in the Notification Settings, please add the <img> tag as shown here

    Hope this helps ??

    Thread Starter klewis

    (@blackawxs)

    Thanks for the feedback!

    So if we can pretend the domain is https://google.com, what would your example look like above?

    Thread Starter klewis

    (@blackawxs)

    Actually that was perfect, and I got it working. Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get root URL’ is closed to new replies.