清新小叶 發表於 2023-10-27 00:00:00

wordpress实现发布文章自动ping 百度

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
为了加快收录情况 除了谷歌勤快点 百度也不能落下</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode13" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
//文章发布主动ping baidu <br>
function pingbaidu($post_id) {<br>
$baiduXML = 'weblogUpdates.extendedPing' . get_option('blogname') . ' ' . home_url() . ' ' . get_permalink($post_id) . ' ' . get_feed_link() . ' ';<br>
$wp_http_obj = new WP_Http();<br>
$return = $wp_http_obj-&gt;post('http://ping.baidu.com/ping/RPC2', array('body' =&gt; $baiduXML, 'headers' =&gt; array('Content-Type' =&gt; 'text/xml')));<br>
if(isset($return['body'])){<br>
if(strstr($return['body'], '0')){<br>
$noff_log='succeeded!';<br>
}<br>
else{<br>
$noff_log='failed!';<br>
}<br>
}else{<br>
$noff_log='failed!';<br>
}<br>
}<br>
add_action('publish_post', 'pingbaidu');</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
复制到主题下面的functions.php中 上传覆盖个试试</p>
頁: [1]
查看完整版本: wordpress实现发布文章自动ping 百度