Programming SEO – Cross Linking Titles


Here is another interesting way to programmatically add link juice to web pages from within your own site.  It will require that you have pages created dynamically from a database and that you have some way of retrieving the title.

You’ll remember that one of the ways of helping a page rank in the search engines is by providing links to that page that say what that page is about.  What better indication of what a page is about than the title?

So what you’ll need to do on each page is to gather a list of all the pages and their titles on your site, search for content on your page that matches each of those titles, and then hyperlink each phrase to the corresponding page on your site.

To do this, I’d recommend using regular expressions.

Given a title of “The Quick Brown Fox” you’d want to find any occurrence of that string that had any number of white space characters between the words and in any mix of casing.

The regular expression for that is:


So, for any title, you’d want to initialize your RegEx like this

Regex rx = new Regex(title.ToLower()
    .Replace(" ", @"\s+"),RegexOptions.IgnoreCase);

This assumes that there is only one space between each of the words in your title.

To replace the text in your article with a hyperlink using this text you’d use

body = rx.Replace(body,
    "<a href='locationOfTheArticleHere'>$0</a>");

This technique works best on page titles that are relatively short.  If your titles tend to be longer, as mine do, you might want to provide a list of possible linking phrases for each article.  In that case, I’d link to the titles first and then make a second pass for the linking terms if and only if a title was not found in the article.

The other obvious problem with this technique is that it could take a long time to generate the page if you have a lot of articles and you do this every time the page is displayed.  If this is the case, you’ll want to implement some caching mechanism either by using what is built into .NET or by using some other implementation that caches on a more permanent basis.

Related Post

One Response to “Programming SEO – Cross Linking Titles”

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail