网站评论功能一直是网站管理员爱恨功能,爱,因为它可以增加网站管理员和用户之间的良好互动,缺点是其他人可以使用他们的评论功能做外部网站,更头痛是这些外部链接不仅会导致网站重量的损失,更有可能导致用户损失。因此,为了尽可能避免这些问题,有必要在这些导出链接中添加后续属性。
通过向导出链接添加后续属性和新窗口,“折叠”网站内容页面自动打开
考虑到一些主题没有这个功能,请共享一个日间导出链接到 WordPress
网站内容页面,以自动添加无跟随属性,并打开一个新窗口,以减少网站的减肥和用户损失。
使用方法:在该函数中输入以下代码。在当前顶部下,php
文件?>汇站网亲测可用)。
使用方法:将以下代码放到当前主题下的 function
.php
文件 ?> 即可(白天亲测可用)。
/** */add_filter
( 'the_content
', 'cn_nf_url_parse
');function
cn_nf_url_parse
( $content
) { $regexp
=if
(preg_match_all
("/$regexp
/siU
", $content
, $matches
,PREG_SET_ORDER
)) {if
( !empty
($matches
) ) { $srcUrl
=get_option
('siteurl
');for
($i
=0; $i
<count
($matches
); $i
++) { $tag
= $matches
[$i
][0]; $tag2
= $matches
[$i
][0]; $url
= $matches
[$i
][0]; $noFollow
= ''; $pattern
= '/target
\s
*=\s
*"\s
*_blank
\s
*"/';preg_match
($pattern
, $tag2
, $match
,PREG_OFFSET_CAPTURE
);if
(count
($match
) < 1 ) $noFollow
.= 'target
="_blank
" '; $pattern
= '/rel
\s
*=\s
*"\s
*[n
|d
]ofollow
\s
*"/';preg_match
($pattern
, $tag2
, $match
,PREG_OFFSET_CAPTURE
);if
(count
($match
) < 1 ) $noFollow
.= 'rel
="nofollow
" '; $pos
=strpos
($url
,$srcUrl
);if
($pos
===false
) { $tag
=rtrim
($tag
,'>'); $tag
.= $noFollow
.'>'; $content
=str_replace
($tag2
,$tag
,$content
); } } } } $content
= ']]>', $content
);return
$content
; }
为此,基本上让 WordPress
网站内容页面导出链接自动添加后续属性并打开新的窗口。
转载请注明:汇站网 » 在导出的链接中自动添加 nofollow
属性和新窗口后,将打开 WordPress
站点的内容页