Custom outbound-link qualification
-
I am looking for advice on how to qualify outbound links in web stories with a custom parameter. The UI of the Web Stories plugin allows one to qualify outbound links as “sponsored” or “nofollow” via checkboxes. However, there is no UI option to enter custom parameters.
What I need is a way to qualify the outbound links with the following parameter:data-vars-click-url="https://example-external-website.com"
(the parameter will allow the site analytics to register outbound-link clicks).Currently, links on published web stories look like this:
<a href="https://example-external-website.com" target="_blank" rel="noopener noreferrer" class="_254c3af" i-amphtml-orig-tabindex="0" tabindex="0"> ... </a>
I need the links to look like this:
<a href="https://example-external-website.com" target="_blank" rel="noopener noreferrer" class="_254c3af" i-amphtml-orig-tabindex="0" tabindex="0" data-vars-click-url="https://example-external-website.com"> ... </a>
The order of parameters inside the <a> tag doesn’t matter.
Adding the parameter ought to possible with a code snippet or a site-specific plugin. I have a rough idea of what such a plugin would need to do:- For every link on a web story page, fetch the link URL.
- Check whether the URL is the home domain.
- If no (i.e. if the link is outbound), print the custom parameter with the URL into the <a> tag.
I would appreciate any direction or advice on what functions, hooks, and actions may be helpful to write such code. Any links to code examples with similar functionality are also appreciated.
- The topic ‘Custom outbound-link qualification’ is closed to new replies.