HowTo – WordPress Create Your Own Automatic Text Link Ads In Your Content

Filed under: Wordpress Tips

There are a few companies out there that offer Text Replacement Link Ads to help you gain more income from your content but if you want to control your own Text Link Ads there is a relatively easy way to do this without getting caught up in complex javascript and external services.

Basically what you need to do is read your the_content data before it is sent to your visitors browser and then do a string replace based on key words that  you define.

The following example should be placed in your functions.php file.
to add more keywords place a coma at the end and start a new line.
I suggest you don’t go crazy with the number of links you create.

As an option the add_filter is provided for both your the_content and the_excerpt blocks but you should probably limit this tool to only the_content so it shows on single pages. That is up to you.

How fancy you get is also up to you and you could show a simple link as we are here or a hover javascript that shows a block of info to your viewers..


function my_textlink_ads($text){
$replace = array(
// ‘Find This’ => ‘Replace It With This’
‘chicken’ => ‘<a href="">chicken</a>’,
‘hamburgers’ => ‘<a href="">hamburgers</a>’
$text = str_replace(array_keys($replace), $replace, $text);
return $text;

add_filter(‘the_content’, ‘my_textlink_ads’); // to replace in the_content
add_filter(‘the_excerpt’, ‘my_textlink_ads’); // to replace in the_excerpt


Now you can create your own textlink ads without the need for a external service.