| /**
 * WordPress 自动为文章标签添加该标签的链接
 */
function wpkj_auto_add_tag_link($content){
    $limit = 1; // 设置同一个标签添加几次链接
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            $link = get_tag_link($tag->term_id);
            $keyword = $tag->name;
            $cleankeyword = stripslashes($keyword);
            $url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), __('View all posts in %s')).'">'.addcslashes($cleankeyword, '$').'</a>';
            $regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
            $content = preg_replace($regEx,$url,$content,$limit);
        }
    }
    return $content;
}
//add_filter( 'the_content', 'wpkj_auto_add_tag_link', 1 );
 wordpress 自动为文章添加标签内链自动内链功能 |