WordPress自動檢測並顯示文章是否被百度收錄
阿新 • • 發佈:2020-12-07
開啟自己正在使用的主題的檔案目錄(/wp-content/themes/主題名),找到functions.php。編輯functions.php,在底部加入下面的程式碼:
/* 檢查百度是否已收錄文章頁面 開始*/ function baidu_check($url){ $url=\'http://www.baidu.com/s?wd=\'.$url; $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); $rs=curl_exec($curl); curl_close($curl);if(!strpos($rs,\'沒有找到\')){return 1; }else{return 0; } }function baidu_record() {if(baidu_check(get_permalink()) == 1) {echo \'<a target=\"_blank\" title=\"點選檢視\" rel=\"external nofollow\" href=\"https://www.baidu.com/s?wd=\'.get_the_title().\'\">百度已收錄</a>\'; } else {echo \'<a style=\"color:red;\" rel=\"external nofollow\" title=\"一鍵幫忙提交給百度,謝謝您!\" target=\"_blank\" href=\"https://zhanzhang.baidu.com/sitesubmit/index?sitename=\'.get_permalink().\'\">百度未收錄</a>\'; } }
呼叫方法:
<?php baidu_record();?>新增到你想要顯示的位置!上面的程式碼新增完成後,將插入到需要顯示收錄提示的地方,一般文章模板是single.php,頁面模板是page.php。新增好後重新整理頁面,收錄提示能夠正常顯示就說明ok了。