在新窗口打开WordPress文章中的链接,让文章中的所有链接都在新窗口打开。要实现这个功能,你可以在添加链接的时候,可以手动选择打开方式(给链接添加 target=_blank”属性)。下面介绍一种方法自动实现该功能:只需要在你的WordPress主题的 functions.php 的最后一个 ?> 前添加下面的代码就可以了:
function autoblank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
add_filter('the_content', 'autoblank');
或者加入
<h2><a href="<?php the_permalink() ?>" target="_blank"title="<?php the_title(); ?> - <?php bloginfo('name'); ?>"><?php the_title(); ?></a></h2>