Blog Mechanics Keyword Link Plugin v0.3.1
This is a little plugin that helps you to automatically link defined keywords to certain articles on your own blog, or elsewhere on the internet.
The inspiration for this plug-in comes from a website which I am writing. It has a lot of touristic information and it would be great if every important keyword would automatically be linked to its relevant articles instead of me having to do this by hand.
Let say that I have written an article about Stonehenge. Each time I now write a post that mentions Stonehenge, it should automatically link to that article.
A visit to the UK is not complete without a visit to Stonehenge."
Becomes:
A visit to the UK is not complete without a visit to stonehenge.
Screenshot

Installation
- Just download the ZIP file, and unpack it in the /wp-content/plugins directory.
- Activate the plugin
- Enter your keyword-link pairs in the option panel for the plug-in.
v0.2
If you would like to modify the style of the link. For example to make the link bold add the following to your style.css file:
.bm_keywordlink { font-weight: bold; }
v0.3.1
It is now possible to specify per link if you would like to :
- Link only the first mention of the keyword in the article (or all, which is the default)
- Tag a link as “nofollow” , useful for external links.
The replacement routine is also smarter about linking keywords. For example: “magic” will match “magic” , but no longer to “magically”.

Hello Martin
I would like to ask you before I install the plugin if the word “Stonehenge” is repeated in the same post several times, will all be linked as well?
I think this shouldn’t happen..
Hoi Aouni,
Yes, it will replace all occurrences, not just the first . A side effect of using the
str_replacefunction used for this.Interesting point — I will look into making this an option. Something like “(x) only replace first match”
Would that work?
Cheers,
Martin
I modified the code a little to support replacing only the first occurance of a keyword. For instructions, please see the introduction above.
Hope this helps.
Cheers,
Martin
I modified the code to allow for nofollowing and opening in a new window any link off of my domain. Perhaps integrate for the next release?
Hoi Trick,
Thanks for the suggestion.
Should be easy to integrate — it seems however that the “simple” is slowly giving way to “features”.
If I find a moment I will add an option panel to the configuration allowing for (1) first occurance replacement (2) no follow tags for external links (3) open in a new window all as options.
Cheers,
Martin
Hello! Good work!
However, there are a few glitches that might need attention.
If I have put one URL for the key word “magic” and another URL for “magicians”, then the latter don’t work, as the first word/link is too greedy and URL-ifies it like this: (MAGIC)ians.
It also cuts into URLs already in the text.
Like the text:
http ://magic.performance.net becomes
http ://(MAGIC).performance.net
Also… but I’m not quite sure of it yet, but it seems like it also in some cases, cuts into the already generated link. Like it check for keywords in a string even after a URL already has been assigned… Not sure yet, but I’ve gotten strange results hard to explain otherwise.
While trying it out, I also experimented with getting the title attribute into the generated link. I did it quite simple. In the link field, I put the URL and a title phase together, separated with a vertical bar | and then used the explode function during the replacement. A little later, I expanded the idea to:
http://www.thesite.com|A good site|N|F
Then in the code, that got exploded into:
The URL, a phrase for the title attribute, N becomes rel=nofollow, and F for replacing the First occurrence only. A bit messy perhaps, but it was quicker than to modify all the form fields and such.
Previously, in Joomla, I’ve used “Ludo Autolinkbot”, which works perfectly as far as I’ve noticed. Perhaps it would be interesting to see how the tricky bits are solved there? It can be found here:
http ://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1575/Itemid,35/
(sorry if I’m duplicating a post, but nothing seemed to happen when I pressed submit)
Hoi Tom,
Your problems are caused by the plug-in’s simplistic search & replace routine. When I wrote it, I just needed to replace a few noun’s (Stonehenge does change much
)
The solution is simple: a little more advanced pattern match routine that ensures that each match is on a word boundary. I will find some time and modify the code.
I will also have a look at the Joomla plugin you mentioned for ideas. Seems “simple” is over.
Cheers,
Martin
Great little plugin for SEO. I made a little improvement that you might want to check out - made matching case-insensitive, but the case from the document is preserved.
For example, say the keyword in the db is StOneHenge, and your article has “Stonehenge” in it. The text will match, and the link anchor will be “Stonehenge” from the article.
I did this by making a small mod to the replace function. Here’s my version:
function bm_keywordlink_replace($content)
{
$links = get_option(BM_KEYWORDLINK_OPTION);
if ($links)
foreach ($links as $keyword => $details)
{
list($link,$nofollow,$firstonly) = explode(”|”,$details);
$url = ” “;
$url .= “$0“;
$url .= ” “;
if ($firstonly) $limit = 1; else $limit=-1;
$content = preg_replace(”/\b$keyword\b/i”,$url,$content,$limit);
}
return $content;
}
You can see it in action on my blog: The Million-Dollar Dime
Cheers,
Sean
Whoops, messed up the link. Here’s the real one: The Million-Dollar Dime
Hoi Sean,
Many thanks for the suggestion. I’ll look into it when I have a moment. Success with reaching a million!
Cheers,
Martijn
This plugin works well enough (my old autolinks plugin doesn’t seem to work with 2.5.1) but I’d like to make some suggestions:
1. Ability to add more than one link at a time (batch add, 5 or more).
2. Ability to edit/modify links (didn’t realize they were case sensitive, saw no way to edit, had to add a new one).
3. Option to open links in new window (I modded the file to do this already).
4. Bug: I had a link that had a keyword in the title attribute (title=”keyword”), and I got a weird error when I hovered over the link. It’s like it was trying to auto-link it. On a related note, I already did some manual links for keywords I’d like to add, and it auto-linked those as well. Would be nice if it would somehow ignore the ones that are already links.