1. Proactive push
Open the functions. php template function file in the WordPress theme file, at the end (?> Add the following code.
If (! Function_exists ('Baidu _ Submit ')){
Function Baidu_Submit ($ post_ID ){
$ WEB_TOKEN = 'xxxxxxxx' // Here, replace it with the token value pushed by Baidu on your website.
$ WEB_DOMAIN = get_option ('Home ');
// Successfully pushed articles are no longer pushed
If (get_post_meta ($ post_ID, 'baidusubmit ', true) = 1) return;
$ Url = get_permalink ($ post_ID );
$ Api = 'http: // data.zz.baidu.com/urls? Site = '. $ WEB_DOMAIN.' & token = '. $ WEB_TOKEN;
$ Request = new WP_Http;
$ Result = $ request-> request ($ api, array ('method' => 'post', 'body' => $ url, 'headers' => 'Content-Type: text/plain '));
$ Result = json_decode ($ result ['body'], true );
// If the push is successful, add the custom bar Baidusubmit in the article. The value is 1.
If (array_key_exists ('success', $ result )){
Add_post_meta ($ post_ID, 'baidusubmit ', 1, true );
}
}
Add_action ('Publish _ post', 'Baidu _ Submit ', 0 );
}
The web_token in the above code is changed to your own, which can be obtained through the Baidu webmaster background link submission page. In the code, baidusubmit mainly prevents repeated push after the article is published due to updates.
2. Automatic push
Open the bottom file of footer. php in the WordPress theme file and add the following javascript code to it.
3. sitemap push
Use google or Baidu's sitemap plug-in to generate a sitemap. xml page and submit it to the Baidu webmaster's background.
The above three methods are used to push the new link of the article to Baidu to quickly include the new page of the website. In a few days, you can see the number of links pushed to Baidu every day in the background.