wordpress发布文章主动推送到百度PC端的收录

作者: Arvin Chen 分类: Wordpress 来源: Break易站(www.breakyizhan.com)

这篇文章主要讲的是wordpress发布文章主动推送到百度PC端的收录。 为了查找方便,小A汇总了所有wordpress的相关教程,方便大家查找到自己想要的wordpress教程:  wordpress教程汇总。此外,还汇总了汇总了所有SEO优化的相关教程: SEO优化教程汇总


我们前面已经有一篇文章讲到了wordpress发布文章主动推送到熊掌号的原创收录 – Break易站,那么推送到百度熊掌号的我们已经做了,那么为了百度PC页面更好的收录,我们这一篇文章就是说如何用PHP推送到百度PC页面。只要把下面的代码写到funtions.php里面,发布文章的时候就会自动推送到百度了哦!

百度PHP推送的token

在百度站长的链接提交里找到自己的php推送的token,如下

 

wordpress发布文章主动推送到百度PC的收录

在functions.php下面加入下面的代码即可,记得把www.breakyizhan.com和yourtoken改成自己的网址和token,选用的是php自动推送到原创文章


<?php 
date_default_timezone_set('Asia/Shanghai'); add_action('publish_post', 'publish_bd_submit', 999); 
function publish_bd_submit($post_ID){ global $post; 
$bd_submit_enabled = true; 
if($bd_submit_enabled){
$api ='http://data.zz.baidu.com/urls?site=www.breakyizhan.com&amp;token=yourtoken';
if($post-&gt;post_status != "publish"){
$url = get_permalink($post_ID);
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain')
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
// $result = json_decode($result, true);
$time = time();
$file = dirname(__FILE__).'/by_baiduSubmit.txt';//生成日志文件,与代码所处文件同目录
if(date('Y-m-d',filemtime($file)) != date('Y-m-d')){
$handle = fopen($file,"w");
}else{
$handle = fopen($file,"a");
}
$resultMessage="";
if($result['message']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交失败".$result['message'].":\n网址:".$url."\n\n".$result;
}
if($result['success']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交成功".":".$url."\n\n";
}
fwrite($handle,$resultMessage);
fclose($handle);
}
}
}

?>

 

wordpress发布文章主动推送到百度PC的收录和百度熊掌号的收录

那么结合我们另外一篇文章,wordpress发布文章主动推送到熊掌号的原创收录 – Break易站,可以整合wordpress发布文章同时主动推送到百度PC的收录和百度熊掌号的收录, 也是在functions.php添加如下代码,记得下面有四个地方需要改成自己的yourID,your熊掌号token,www.breakyizhan.com和yourtoken(PC的token)。


<?php 
date_default_timezone_set('Asia/Shanghai'); add_action('publish_post', 'publish_bd_submit', 999); 
function publish_bd_submit($post_ID){ global $post; 
$bd_submit_enabled = true; 
if($bd_submit_enabled){ 
$api ='http://data.zz.baidu.com/urls?appid=yourID&token=your熊掌号token&type=realtime,original'; if($post->post_status != "publish"){
$url = get_permalink($post_ID);
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain')
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
// $result = json_decode($result, true);
$time = time();
$file = dirname(__FILE__).'/by_baiduSubmit.txt';//生成日志文件,与代码所处文件同目录
if(date('Y-m-d',filemtime($file)) != date('Y-m-d')){
$handle = fopen($file,"w");
}else{
$handle = fopen($file,"a");
}
$resultMessage="";
if($result['message']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交失败".$result['message'].":\n网址:".$url."\n\n".$result;
}
if($result['success']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交成功".":".$url."\n\n";
}
fwrite($handle,$resultMessage);
fclose($handle);
}
}

if($bd_submit_enabled){
$api ='http://data.zz.baidu.com/urls?site=www.breakyizhan.com&token=yourtoken';
if($post->post_status != "publish"){
$url = get_permalink($post_ID);
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain')
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
// $result = json_decode($result, true);
$time = time();
$file = dirname(__FILE__).'/by_baiduSubmit.txt';//生成日志文件,与代码所处文件同目录
if(date('Y-m-d',filemtime($file)) != date('Y-m-d')){
$handle = fopen($file,"w");
}else{
$handle = fopen($file,"a");
}
$resultMessage="";
if($result['message']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交失败".$result['message'].":\n网址:".$url."\n\n".$result;
}
if($result['success']){
$resultMessage= date('Y-m-d G:i:s',$time)."\n提交成功".":".$url."\n\n";
}
fwrite($handle,$resultMessage);
fclose($handle);
}
}
}

?>

本文内容来自:wordpress发布文章主动推送到百度PC端的收录 – Break易站


—Author: Arvin Chen —Web Address: www.breakyizhan.com (Break易站)

  •   本文标题:wordpress发布文章主动推送到百度PC端的收录 - Break易站
    转载请保留页面地址:https://www.breakyizhan.com/wpress/1402.html
      微信返利机器人
      免费:淘宝,京东,拼多多优惠券
      腾讯,爱奇艺,优酷的VIP视频免费解析,免费看
      即刻扫描二维码,添加微信机器人!

    发表笔记

    电子邮件地址不会被公开。 必填项已用*标注