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.