[WP plugin] 讓文章內的連結皆為另開新視窗

作者: zonble

外掛程式如下,存成.php檔案後,放在wp-content/plugins/,然後啟用即可。

<?php

/*
Plugin Name: External Links
Plugin URI: http://zonble.twbbs.org/
Description: Add "target='_blank'" tag to all your links in your stories, and as the visitors click on the links in your stories, it will open a new browsing window.
Author: Weichung Yang
Author URI: http://zonble.twbbs.org/
*/

if (function_exists('add_filter')) {
function __target_blank($content) {
$content = preg_replace_callback("/<a href="([^>]*)>/is",
'__target_blank_back',
$content);
return $content;
}

function __target_blank_back($match) {
$code = $match[1];
if(!strstr($code, get_bloginfo('URL'))){
$code .= " target="_blank"";
}

return "<a href="$code>";
}

add_filter('the_content', '__target_blank');
}

?>

Bookmark to del.icio.usBookmark to furlBookmark to Blinklist

One Response to “[WP plugin] 讓文章內的連結皆為另開新視窗”


  1. 你這裡真是太棒了!我的問題都有了答案:)