1 Star 0 Fork 40

Nuet/wordpress-theme-puock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fun-custom.php 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
Licoy 提交于 2023-01-27 15:43 . :sparkles:增加用户中心基础框架和展示
<?php
/**
* 其他外部引用函数方法
* ==================
*/
/**
* 给外链加上nofollow及新窗口打开
* from: https://cn.wordpress.org/plugins/nofollow-for-external-link/
* license: GPL-2.0
*/
if(!function_exists('cn_nf_url_parse')){
function cn_nf_url_parse( $content ) {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
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 = str_replace(']]>', ']]>', $content);
return $content;
}
}
add_filter( 'the_content', 'cn_nf_url_parse');
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/Nuet/wordpress-theme-puock.git
git@gitee.com:Nuet/wordpress-theme-puock.git
Nuet
wordpress-theme-puock
wordpress-theme-puock
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385