国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

wordpress中設置評論鏈接重定向跳轉且加Nofollow屬性

2024-09-07 00:50:16
字體:
來源:轉載
供稿:網(wǎng)友

現(xiàn)在推廣人員無處不在我們的Wordpress博客他們都不放過,下面我來介紹在博客評論中我們加上重定向跳轉且加Nofollow屬性的方法.

WordPress設置評論鏈接重定向跳轉

首先在主題目錄下的函數(shù)模板<functions.php>的最后?>位置添加如下代碼:

  1. //comments link redirect // 以下是我添加的wordpress設置評論鏈接重定向跳轉 
  2. add_filter('get_comment_author_link''add_redirect_comment_link', 5); 
  3. add_filter('comment_text''add_redirect_comment_link', 99); 
  4. function add_redirect_comment_link($text = ''){ 
  5. $text=str_replace('href="''href="'.get_option('home').'/?r='$text); 
  6. $text=str_replace("href='""href='".get_option('home')."/?r="$text); 
  7. return $text
  8. add_action('init''redirect_comment_link'); 
  9. function redirect_comment_link(){ 
  10. $redirect = $_GET['r']; 
  11. $host = $_SERVER['HTTP_HOST']; 
  12. if($redirect){ 
  13. if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){ 
  14. header("Location: $redirect#form:$host"); 
  15. exit
  16. else { 
  17. header("Location: $redirect#form:$host"); 
  18. exit

以上是我添加的wordpress設置評論鏈接重定向跳轉

這樣URL跳轉是基本完成了,接下來就是要實現(xiàn)超鏈接在新窗口中打開了,打開wp-includes目錄下的comment-template.php文件,到第147行左右的get_comment_author_link()函數(shù)(也就是function get_comment_author_link( $comment_ID = 0 )),在第155行else $return 這行標簽里加入target=‘_blank’屬性,修改后上傳即可,完整的代碼貼上來:

  1. function get_comment_author_link( $comment_ID = 0 ) { 
  2.  /** @todo Only call these functions when they are needed. Include in if... else blocks */ 
  3.  $url    = get_comment_author_url( $comment_ID ); 
  4.  $author = get_comment_author( $comment_ID ); 
  5.  if ( emptyempty$url ) || 'http://' == $url ) 
  6.   $return = $author
  7.  else 
  8.   $return = "<a href='$url' rel='external nofollow' target=‘_blank’ class='url'>$author</a>"
  9.  return apply_filters('get_comment_author_link'$return); 

根據(jù)下面圖里在第一句的nofollow后面增加一個target=”_blank”。

設置評論鏈接Nofollow屬性

wordpress的評論鏈接添加Nofollow屬性和設置URL跳轉,來避免垃圾評論,垃圾鏈接對自己博客質量的影響,你可以通過下面在 functions.php函數(shù)文件修改這段代碼,代碼如下:

  1. add_filter('get_comment_author_link''add_redirect_comment_link', 5); 
  2. add_filter('comment_text''add_redirect_comment_link', 99); 
  3. function add_redirect_comment_link($text = ''){ 
  4. $text=str_replace('href="''href="'.get_option('home').'/?r='$text); 
  5. $text=str_replace("href='""href='".get_option('home')."/?r="$text); 
  6. return $text
  7. add_action('init''redirect_comment_link'); 
  8. function redirect_comment_link(){ 
  9. $redirect = $_GET['r']; 
  10. if($redirect){ 
  11. if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){ 
  12. header("Location: $redirect"); 
  13. exit
  14. else { 
  15. header("Location: http://m.survivalescaperooms.com/"); //這個鏈接換成你自己網(wǎng)站 
  16. exit

以上就是怎樣給wordpress的評論鏈接添加Nofollow屬性和設置評論鏈接重定向跳轉的方法.

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宝清县| 额尔古纳市| 伊宁市| 台安县| 健康| 繁峙县| 新沂市| 垫江县| 潮安县| 始兴县| 安阳市| 隆化县| 崇左市| 肇源县| 安仁县| 静海县| 贵德县| 石城县| 永登县| 平武县| 亚东县| 根河市| 济南市| 资兴市| 潍坊市| 榆树市| 武乡县| 交城县| 芮城县| 阜康市| 株洲市| 汪清县| 民和| 瑞金市| 河间市| 驻马店市| 宝山区| 玛多县| 双流县| 资溪县| 乐平市|