Add automatically link to a specific word in WordPress

As I mentioned in SEO Basics linkbuilding is crucial to improve your rankings in search engines. One solution is to have links added by yourself. However, you know how annoying is to click/write and add every time a link to your posts or to a specific keyword every time. Why don’t you make it automatic? To add automatically link to a specific word in WordPress is easy. Just add your word and replace it with a simple link. You can play with the code. Add styling such as  bold or italic, make an abbreviation and so on. Best use to add your internal links to your specific keywords so you can link easy.

For example, my article about Search Engine Optimization – Basics will get an automatic link if I type SEO Basics.

Add this code in functions.php

function replace_keywords($text){
	$replace = array(
		// 'Keyword' => 'REPLACE WORD WITH'
		'FB' => '<a href="">Facebook</a>',
		'Google' => '<a href=""><b>Google</b></a>',
		'SEO Basics' => '<a href="/blog/seo/">SEO Basics</a>',
	$text = str_replace(array_keys($replace), $replace, $text);
	return $text;
add_filter('content_save_pre','replace_keywords' );
add_filter('the_excerpt', 'replace_keywords');

As you can see the ‘content_save_pre’ makes it possible to see the changes even in draft mode, while the_excerpt makes clickable the links in excerpt (short summary).


Internal linking is important, but not overwhelming, complicated, or difficult. The great thing is, you’ll experience a stronger link profile and better SEO by consistent internal linking. It’s even worth it to go back and audit your old content to make sure it has sufficient internal linking.

What do you think? Do you have a better solution? Share in the comments below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.