如果使用过滤器“the\\u content”,则可以使用以下组合preg_... 语句循环所有链接,将target=“\\u blank”添加到符合您特定需求的链接中。可以将此筛选器添加到函数中。php,或选择页面、帖子或类别templates .
add_filter( \'the_content\', \'ex1_the_content_filter\' );
function ex1_the_content_filter($content) {
    // finds all links in your content
    preg_match_all(\'/(\\<a href=.*?a>)/\',$content,$matches, PREG_SET_ORDER);
    // loop through all matches
    foreach($matches as $m){
        // potential link to be replaced...
        $toReplace = $m[0];
        // if current link does not already have target="{whatever}"
        // You can add whatever additional "IF" you require to this one
        if (!preg_match(\'/target\\s*\\=/\',$toReplace)){
            // adds target="_blank" to the current link
            $replacement = preg_replace(\'/(\\<a.*?)(\\>)(.*?\\/a\\>.*?)/\',\'$1 target="_blank"$2$3\',$toReplace);
            // replaces the current link with the $replacement string
            $content = str_ireplace($toReplace,$replacement,$content);
        }
    }
      return $content;
}