Elementor: Make Only a Dynamic Tag a Link and Not Before or After Text

Smart Web Creative - Elementor: Make Only a Dynamic Tag a Link

If you have ever wanted to make a dynamic tag within Elementor a link, you will come to find that when you place the before or after text within the Advanced options, it makes those parts of the link as well. Well, what if you wanted to have ONLY the dynamic tag be the portion that has the link on it? In this article, we will go over how to make only a dynamic tag a link and not the “before” or “after” text.

To do this, we’re assuming that you have Elementor Pro, ACF, and access to the functions.php file of your theme. Also, you’re probably wanting to do this within a custom loop using Ele Custom Skin.

Adding the Shortcode for Link on Dynamic Tag Only Code

The first thing you will want to do is copy the following code and paste it into your theme’s function.php file. What this code does is it makes a shortcode for your dynamic tag link that you can utilize elsewhere:


/* Shortcode for Link on Dynamic Tag Only */
function link_dynamic_tag_only_shortcode_function() {
$link_url = get_post_permalink();// Grab the URL for the post in the loop
$dynamic_link_text = get_field('custom_field_name');// Change "custom_field_name" to the name of your custom field
$output = '<a href="' . $link_url . '">' . $dynamic_link_text . '</a>';
return $output;
}
add_shortcode( 'dynamic_tag_link_shortcode', 'link_dynamic_tag_only_shortcode_function' );// "dynamic_tag_link_shortcode" is the name of the shortcode
/* Shortcode for Link on Dynamic Tag Only */

Be sure to change the code above to work with your ACF custom field setup. You will also want to copy “dynamic_tag_link_shortcode”, which is going to be the name of your shortcode.

Adding Your Dynamic Tag Widget to Your Page or Loop

In this next step, you can use either the Text Editor widget or the Heading widget. For this article, we’ll be using the Heading widget.

When you add your dynamic tag, normally you would use the ACF Field option. However, we want to use in this case, the Shortcode option.

Next, for the actual shortcode, paste what you copied from the functions.php file and add brackets around it like so, [dynamic_tag_link_shortcode].

In the “Advanced” options, you can add whatever you’d like that will come before and after the dynamic tag. In this example, we are using “Learn more about ” for the before and “.” for the after. Be sure to include the space at the end of the before, otherwise, your result will look like this, “Learn more aboutthis link”.

 

That should be it. If you use this in a loop, you will see that each before and after are the same, but the dynamic part that is a link will change both its text and the link.

Other Helpful Articles

Choosing A Domain Name

Selecting a domain name for your website is one of the first things a website needs and probably one of the most difficult. The domain name is what someone types into the URL box on a browser to get to a site. Think of it as an unique location identifier

Read More »

How To Create an Email Signature in Gmail/G Suite

You may have noticed many businesses and individuals will have email signatures that look professional. If you have Gmail or G Suite, there’s actually a pretty easy way to set one up. To start creating your email signature, sign in to your Gmail account. Over in the top right you’ll

Read More »

Use Gmail for Webmail Accounts

If you use Gmail and you have a Webmail account, you can actually use Gmail for your Webmail accounts. There are some benefits, but also drawbacks to using this setup. It is important though that before you take the following steps, you ensure that your DNS records have the correct

Read More »

What Do You Need Done?:

(Please check all that apply)

Tell Us About You

Almost Done!

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info