把以下全部代码复制到你的模板函数 (functions.php) 注:模板不同,有些会是在:(functions-theme.php)
/*-----------------------------------------------------------------------------------*/ /* WordPress文章内外链添加go跳转 / * https://www.juan920.com/73.html /*-----------------------------------------------------------------------------------*/ function loper_content_nofollow($content){ preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches); if($matches){ foreach($matches[2] as $val){ if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){ $content=str_replace("href="$val"", "href="".get_stylesheet_directory_uri()."/go.php?url=$val" ",$content); } } } return $content; } add_filter('the_content','loper_content_nofollow',999); /*-----------------------------------------------------------------------------------*/ / * https://www.juan920.com/73.html /* WordPress评论者链接添加go跳转 /*-----------------------------------------------------------------------------------*/ function loper_redirect_comment_link($text = ''){ $text = str_replace('href="', 'href="'%20. get_stylesheet_directory_uri() . '/go.php?url=', $text); $text = str_replace("href='", "href='" . get_stylesheet_directory_uri() . "/go.php?url=", $text); return $text; } add_filter('get_comment_author_link', 'loper_redirect_comment_link', 5); add_filter('comment_text', 'loper_redirect_comment_link', 99);
如果我的文章对你有帮助,欢迎移至上方按钮打赏
© 版权声明
THE END