Appending Hyperlink with Tag using PHP
-
I am finding a way to append the hyperlink with some tag or keyword using PHP if some specified keyword exists in the hyperlink on whole wordpress site or only in the post content. I am currently doing this by javascript, but a server level solution is needed as javascript is not allowed in amp pages.
The current javascript is:-<script type='text/javascript'> var links = document.getElementsByTagName('a'); for(var i = 0; i< links.length; i++){ if(links[i].href.indexOf("amazon.in") > -1) { if(links[i].href.indexOf("?") > -1) { links[i].href = links[i].href + "&tag=chaklesh-21"; } else links[i].href = links[i].href + "?tag=chaklesh-21"; } else if(links[i].href.indexOf("flipkart.com") > -1) { if(links[i].href.indexOf("?") > -1) { links[i].href = links[i].href + "&affid=tricknsho"; } else links[i].href = links[i].href + "?affid=tricknsho"; } else if(links[i].href.indexOf("nayag.com") > -1) { links[i].href = links[i].href ; } else if(links[i].href.indexOf("dmca.com") > -1) { links[i].href = links[i].href ; } else if(links[i].href.indexOf("facebook.com") > -1) { links[i].href = links[i].href ; } else { links[i].href = "https://linksredirect.com/?pub_id=13124CL11885&source=linkkit&url=" + links[i].href ; } } </script>
Please help me in getting its equivalent output via PHP in WordPress. Thanks in Advance ??
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Appending Hyperlink with Tag using PHP’ is closed to new replies.