fix: content nofollow (#335)

pull/343/head
Seaton Jiang 2021-02-18 13:56:35 +08:00
parent 9994ec7a48
commit 94d8289820
No known key found for this signature in database
GPG Key ID: C1086BAE716FF138
1 changed files with 4 additions and 4 deletions

View File

@ -3,13 +3,13 @@
* 文章相关函数 * 文章相关函数
* @author Seaton Jiang <seaton@vtrois.com> * @author Seaton Jiang <seaton@vtrois.com>
* @license MIT License * @license MIT License
* @version 2021.01.06 * @version 2021.02.18
*/ */
// 文章链接添加 target 和 rel // 文章链接添加 target 和 rel
function imgnofollow($content) function content_nofollow($content)
{ {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>"; $regexp = "<a\s[^>]*href=['\"][^#]([^'\"]*?)\\1[^>]*>";
if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) { if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
if (!empty($matches)) { if (!empty($matches)) {
$srcUrl = get_option('siteurl'); $srcUrl = get_option('siteurl');
@ -42,7 +42,7 @@ function imgnofollow($content)
$content = str_replace(']]>', ']]>', $content); $content = str_replace(']]>', ']]>', $content);
return $content; return $content;
} }
add_filter('the_content', 'imgnofollow'); add_filter('the_content', 'content_nofollow');
// 文章点赞 // 文章点赞
function love() function love()