最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to Replace Words with Hypertext Link But Ignore Previously Existed Links?

programmeradmin1浏览0评论

Auto-linking for "selected words" in the_content I am currently using the following code:

function wp_affiliate_links($text){
    $replace = array(

'/ example /' => ' <a rel="nofollow" href="http:example">example</a> ',
'/ Google /' => ' <a rel="nofollow" href="http:Google">Google</a> ',
    );
        }
    $text = preg_replace( array_keys($replace), $replace, $text, 1 );
    return $text;
    }
add_filter('the_content', 'wp_affiliate_links');

But the problem is that - it also try to replace the word that's already hyperlinked and spoils the whole code. If word "example" or Google are linked or comes into a previously linked phrase then it replace (and mess) inside the <a hreaf=""> tag too.

I want it to ignore few tags like <a>, <h1>, <button> etc. I've tried a lot but no luck.

发布评论

评论列表(0)

  1. 暂无评论