Discuz X3.5帖子内容中的外部链接加上rel=nofollow方法是什么
后端开发
39 人阅读
|
1 人回复
|
2024-03-20
|
本帖最后由 求知者 于 2024-3-20 11:52 编辑
帖子里的外链 a标签居然没有 rel="nofollow",对SEO很不友好,有什么方法能添加rel="nofollow"属性?
|
|
|
|
|
|
|
大神
发表于 2024-3-20 11:48:00
|
显示全部楼层
给Discuz! 帖子外链自动添加nofollow的方法
打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改:
- function parseurl($url, $text, $scheme) {
- global $_G;
- if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
- $url = $matches[0];
- $length = 65;
- if(strlen($url) > $length) {
- $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
- }
- $nofllow = strpos($url, $_G['siteurl']) !== 0 ? '" rel="nofollow' : ”;
- return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).$nofllow.'" target="_blank">'.$text.'</a>';
- } else {
- $url = substr($url, 1);
- if(substr(strtolower($url), 0, 4) == 'www.') {
- $url = 'http://'.$url;
- }
- $url = !$scheme ? $_G['siteurl'].$url : $url;
- $nofllow = strpos($url, $_G['siteurl']) !== 0 ? '" rel="nofollow' : ”;
- return '<a href="'.$url.$nofllow.'" target="_blank">'.$text.'</a>';
- }
- }
复制代码
|
|
|
|
|
|