Invalid solution for wordpress using ping Baidu

Source: Internet
Author: User


Next I will quote a few words in the pacifier article

Due to the recent winter vacation, Mr. V also liked to analyze website logs. Recently, when analyzing logs, Mr. V found that after the ping notification service was added, each update is a Google spider, and Baidu spider does not come at all. It is reasonable to say that even if Baidu spider is no longer a big name, it cannot be used once. After all, Baidu also supports the ping protocol. After carefully studying several times, Mr. V found that Baidu was still playing a big game. Major vendors, including Wordpress, use the default ping service with three parameters, namely the website name, the homepage address is the feed address, while the ping of Baidu is the four parameters, namely, the website name, the homepage address, the address of the new webpage, and the feed address. Therefore, the default wordpress ping notification service cannot notify Baidu...
Knowing the principle of failure is much easier to solve,

Add the following code to functions. php:

The code is as follows: Copy code

Function bdping ($ post_id ){
$ BaiduXML = 'weblogupdates. extendedPing '. get_option ('blogname '). ''. home_url (). ''. get_permalink ($ post_id ). ''. get_feed_link (). '';
$ Wp_http_obj = new WP_Http ();
$ Return = $ wp_http_obj-> post ('http: // ping.baidu.com/ping/RPC2', array ('body' => $ baiduXML, 'headers' => array ('content-type' => 'text/XML ')));
If (isset ($ return ['body']) {
If (strstr ($ return ['body'], '0 ')){
$ Noff_log = 'succeeded! ';
        }
Else {
$ Noff_log = 'failed! ';
        }
} Else {
$ Noff_log = 'failed! ';
    }
}
Add_action ('Publish _ post', 'bdping ');

Okay, the blogger is waiting for the effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.