Quantcast
Viewing all articles
Browse latest Browse all 9

Automatically Replace words by Affiliate Links

Image may be NSFW.
Clik here to view.
There are many paid plugins that can easily replace  the words by affiliate links but in this post I’d like to share a cool piece of code that can do the same thing for FREE.

It do not give you as much control as the plugins does, but in most cases this code should fit your needs.




Simply paste the code below into your functions.php file.

function replace_text_wps($text){
    $replace = array(
        // 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
        'thesis' => '<a href="http://wpkube.com/go/thesis">thesis</a>',
        'studiopress' => '<a href="http://wpkube.com/go/ninja">ninja</a>'
    );
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');

Don’t forget to enter your words & links as shown in the example code.

The post Automatically Replace words by Affiliate Links appeared first on WPKube.


Viewing all articles
Browse latest Browse all 9

Trending Articles