Automatically Replace Words With Affiliate Links

function auto_add_affiliate_links($text){
    $replace_words = array(
        //text to search => text to replace
        'amazon' => '<a href="">Amazon</a>',
        'ebay' => '<a href="">Ebay</a>',
        'buy at amazon' => '<a href="">buy at amazon</a>'
    $text = str_replace(array_keys($replace_words), $replace_words, $text);
    return $text;

add_filter('the_content', 'auto_add_affiliate_links');
add_filter('the_excerpt', 'auto_add_affiliate_links');
The following two tabs change content below.

Md Jahed

Latest posts by Md Jahed (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *