Using Embed Code? Randomize your Links & Anchor Text

Learn how to not get penalized for your infographics or widgets by using the same links and anchor text in your embed code over and over.

Using Embed Code? Randomize Your Links & Anchor Text

**UPDATE** Australia’s own Tom Johns was awesome enough to turn this into a WordPress Plugin.

One of the recurring questions I get in the office when we’re discussing the launch of widgets and infographics is “how aggressive should we be with the anchor text in the embed code?” This is likely the result of Matt Cutts’ threat on infographics last year and legends of widgets that led to penalties (raise your hand if you knew the Oatmeal used to work at SEOmoz).

With most SEO conundrums I think about them as a developer before I think about them as a marketer. Google’s algorithms and updates look to identify patterns, so the best way to future-proof your link building efforts is not to create any negative patterns. This is true not just of infographics, but also of guest posts and any other link building tactic that’s being run into the ground in the name of “scale.”

When people ask me about the aggressiveness of the anchor text in the embed code, I usually say go with a branded term or you can randomize the anchor text. Here’s how you can do that in PHP.

[code type=php]
function randomAnchor()
{

$anchors = array(‘keyword 1’, ‘keyword 2’, ‘keyword 3’, ‘keyword 4’, ‘keyword 5’);
return $anchors[0,rand(count($anchors)-1)];

}

[/code]
To even a beginner developer the idea is quite simple. Essentially you create a function that takes a list of keywords that you wish to use as anchor text and it picks randomly from the list. The next step is making that function run in the spot where your embed code is rendered in the HTML, like so:

[code type=html]
<textarea>

<img src=”https://www.example.com/image.jpg” alt=”example alt text”>
<a href=”https://www.example.com”><?=echo randomAnchor();?></a>

</textarea>

[/code]

Now what happens is whenever your site loads the embed code randomly pick from the 5 keywords and place it. You can do this for any number of keywords just add,’keyword’to the array like so:

[code type=php]

$anchors = array(‘keyword 1’, ‘keyword 2’, ‘keyword 3’, ‘keyword 4’, ‘keyword 5’, ‘keyword 6’, ‘keyword 7’, ‘keyword 8’, ‘keyword 9’, ‘keyword 10’, ‘keyword 11’, ‘keyword 12’, ‘keyword 13’, ‘keyword 14’, ‘keyword 16’);

[/code]

It will continue to work no matter how many keywords you add to it because the second line of code counts the number of members in the array before it randomly picks from it.

JavaScript Version

Realistically if you’re working on a client’s site it may be a hard sell to get them to install some server side code just to randomize your anchor text. Also a lot of sites are not using PHP and while I could rattle this function off in a variety of different languages, the next best thing would be to do it with JavaScript. To keep this simple and avoid the need to do some sort of find and replace function we’re just going to randomize the whole link rather than just the anchor text and then we’re going to inject it at the bottom of the textarea named “EmbedText”.

[code type=javascript]

<script type=”text/javascript”>

function randomLink()
{

var links = new Array();

links[0] = “<a href=”https://www.example.com/link1″>anchor 1</a>”;
links[1] = “<a href=”https://www.example.com/link1″>anchor 2</a>”;
links[2] = “<a href=”https://www.example.com/link1″>anchor 3</a>”;
links[3] = “<a href=”https://www.example.com/link1″>anchor 4</a>”;
links[4] = “<a href=”https://www.example.com/link1″>anchor 5</a>”;
links[5] = “<a href=”https://www.example.com/link1″>anchor 6</a>”;

EmbedText.value += links[Math.floor(Math.random()*(links.length-1))];

}
</script>
[/code]

Just as with the PHP version you can add as many links as you’d like. Subsequent links would be added by increasing the number in the array index (the number in the brackets) like so:

[code type=javascript]

links[6] = “<a href=”https://www.example.com/link1″>anchor 6</a>”;
links[7] = “<a href=”https://www.example.com/link1″>anchor 7</a>”;
links[8] = “<a href=”https://www.example.com/link1″>anchor 8</a>”;

[/code]

Just be aware that you need to escape the quotations when declaring the links in the array which means you have place a slash () in front of the quotes (“).

When you place your embed code make sure the <textarea> has id=”EmbedText” otherwise it will not work. After you place your embed code on your site place the following code below it.

[code type=javascript]

<script type=”text/javascript”>
randomLink();
</script>

[/code]

As as an SEO I would prefer you place the first code snippet into a file and link to it from the <head> section of the page with the <script type=”text/javascript” src=”filename.js”></script> to help with the page speed (removing inline JS and allowing the browser to cache the code). If you don’t have that option you can place it directly into the <head> tag.

However as this is about avoiding the creation of patterns those of you that are Tinfoil Hat SEOs can feel free to change the names of the functions and the ID on the textarea, but then again if you’re that paranoid you would likely avoid the JavaScript method altogether.

Here’s that code at work (hit reload to see it randomize):
[cc lang=”javascript”]

// <![CDATA[
function randomLink()
{
var links = new Array();
links[0] = “anchor 1“;
links[1] = “anchor 2“;
links[2] = “anchor 3“;
links[3] = “anchor 4“;
links[4] = “anchor 5“;
links[5] = “anchor 6“;
EmbedText.value += links[Math.floor(Math.random()*(links.length-1))];
}
randomLink();
// ]]>
[/cc]

A note on the Paddy Moogan Method

I am a huge fan of the Inception-esque embed code within an embed code method popularized by the magnanimous Paddy Moogan. However if you’re going to use that, I would err on the side of caution and only use branded anchors and links. The concern being that it is only the JavaScript version is not backend-specific and embedding the JavaScript version an easy pattern to detect. In other words if you were to use the PHP version it would only work for users whose sites are using PHP and that’s virtually impossible to determine therefore you will have to use JavaScript.

Bonus Round

Here’s two more PHP functions.

First, the PHP version of randomLink:

[code type=php]
function randomLink()
{

$links = array(‘<a href=”https://www.example.com/link1″>anchor 1</a>’, ‘<a href=”https://www.example.com/link2″>anchor 2</a>’, ‘<a href=”https://www.example.com/link3″>anchor 3</a>’, ‘<a href=”https://www.example.com/link4″>anchor 4</a>’, ‘<a href=”https://www.example.com/link5″>anchor 5</a>’);

return $links[rand(0,count($links)-1)];

}

[/code]

Second, here’s a function that randomizes the link and the anchor text. I would only use this for branded anchor text.

[code type=php]
function randomLinkAndAnchor()
{

$urls = array(‘https://www.example.com/link1’, ‘https://www.example.com/link2’, ‘https://www.example.com/link3’, ‘https://www.example.com/link4’, ‘https://www.example.com/link5’);

$anchors = array(‘keyword 1’, ‘keyword 2’, ‘keyword 3’, ‘keyword 4’, ‘keyword 5’);
$urlIndex = rand(0,count($urls)-1);

$anchorsIndex = rand(0,count($anchors)-1);
return ‘<a href=”‘.$urls[$urlIndex].'”>’.$anchors[$anchorsIndex].'</a>’;

}

[/code]

Have fun!

Mike King

22 Comments

  • Reply

    Good thinking RE: the random anchor text (though I’d use mt_rand). Not a big fan of the JS solution though. Tinfoil hat: on. 🙂

    I could actually see this being made into a WordPress (etc.) plugin. Then you could choose to have one spot in the admin UI *or* on the post/page to make any future updates to the keywords and/or URLs and not have to worry about bothering the devs for changes.

    • Reply

      I’m not a huge fan of the js version either – being client side it’s easy for google to detect as well. If you’re going to try to outflank the algorithms, do your work outside their purview.

    • Reply

      I completely agree with you guys about the JS version. I’m just playing devil’s advocate and providing a solution that someone could then take and rewrite for themselves. I try to make my posts exhaustive.

  • […] Using Embed Code? Randomize your Links Anchor Text, iAcquire Blog […]

  • Reply

    Not that I’m endorsing embedding keyword links in widgets, but…

    Will random work? Each time Google crawls it will see different text and that may flag suspicion or a lack of trust in the link. A bit like how they may detect adverts and banners because they randomly change.

    I’d suspect a stronger solution is to have it chose a random one per embed then stick with it. Maybe by using a hash (or more simply the page id) to uniquely identify each embed and calculating the anchor text to use from that.

    Is there any evidence that a JS version is crawlable, that only the displayed link is picked up and that it passes PageRank?

    • Reply

      Not sure I understand your question in the context of what I’ve presented so let me try to better explain its usage.

      The code will rotate the anchor text in the embed code (not the placement) which means that the anchors being used in your infographics and widgets will not all be the same. In fact they causes the anchor text to be much better distributed than it normally would be.

      So the code doesn’t change the anchor text once it is placed on someone else’s site. It just picks from a variety of options that you set when your site loads and the user would then place the link with that anchor text.

      While Google could potentially crawl every page on the web and reload it multiple times to see if the anchor text in the embed code of the source changes and then keep track of it to see of all of its placements, I don’t know that it’s a valuable use of their resources to stop something that is likely happening in so few places on the web.

      Finally, the JS version doesn’t need to be crawlable because again it is for the visitor to copy and paste the embed code and put it on their site. It’s not for a link placement to rotate.

      Hope that clears it up.

      • Reply

        Sorry, I didn’t understand the full context. I thought this was code in a widget that they used. Like say a WordPress plugin.

        So each user will copy the embed code containing a random link. Only your version will be randomly changing while theirs is a static copy of one version.

        That makes more sense.

  • […] like this post from Mike King on varying anchor text for embedded infographics. A comment was made that it would make a great wordpress plugin, and I […]

  • […] Using Embed Code? Randomize your Links & Anchor Text (iacquire.com) […]

  • Reply

    got to love arrays; nice post Mr. King!

  • […] is to code the widget to automatically vary the anchor text. We’ve tried this in the past, and last week Mike King wrote about the same tactic. But is randomizing your anchor text too shady? Justin Briggs argued with King on Twitter that this […]

  • Andrea Moro
    Reply

    My only concerns, how this constant link change will be seen from search engines. I mean, the solution work fine as long as it stays in the textarea, but I’m sure somebody out of there will certainly do a mistake to start using this in a different manner.

    • Reply

      It won’t be seen as a change by search engines. Once placed on the site owner’s page, it will be static. The embed code box on iAquire’s (or whoever) page will have the changing text.

  • […] you rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there's a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there’s a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] you rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there’s a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] jangkar teks. Mike King, dari iAcquire, menulis pos besar beberapa minggu lalu tentang bagaimana memutar anchor text di WordPress, dan ada WordPress Plugin . Maaf, plugin tersebut untuk WordPress. Mike King menulis […]

  • […] you rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there's a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] you rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there's a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] you rotate the anchor text. Mike King, of iAcquire, wrote a great post a few weeks ago about how to rotate anchor text in WordPress, and there's a WordPress plugin. Sorry, the plugin is for WordPress. Mike King […]

  • […] the above tactics without any repercussions. I.e. change up the author bio for every guest post, cycling in different anchors in your infographic embed codes, […]

  • E-Koncept
    Reply

    I say using your company name or web address is still the safest bet. Better to be safe than sorry.

Leave a Comment

Your email address will not be published. Required fields are marked *

Get The Rank Report

iPullRank's weekly SEO, Content Strategy and Generative AI Newsletter

TIPS, ADVICE, AND EXCLUSIVE INSIGHTS DIRECT TO YOUR INBOX

Join over 4000+ Rank Climbers and get the SEO, Content, and AI industry news, updates, and best practices to level up your digital performance.

Considering AI Content?

AI generative content has gone mainstream.

Discover what that means for your business and why AI generation can be your competitive advantage in the world of content and SEO.