WordPress 外链新窗口打开并添加 nofollow 属性

在 WordPress 站点中插入外链那是不可避免的,对于每个外链都要手动添加“以新窗口/标签打开”并添加 Nofollow 属性让搜索引擎不跟踪,这是一件非常麻烦的事情!所以 WPEXP 这里就与大家分享免插件实现WordPress 外链新窗口打开并添加 Nofollow 属性这个功能。


在当前使用主题的目录下,编辑 functions.php 文件,添加以下代码:

//WordPress 外链新窗口打开并添加 nofollow 属性 - https://wpexp.cn/103.html
function cleris_url($atts, $url = null){
	extract( shortcode_atts(array('title' => null, 'href' => null), $atts) );
	return '<span class="u-download"><a target="_blank" title="'.$title.'" href="'.$href.'" rel="external nofollow" target="_blank">'.$url.'</a></span>';
}