WordPress articles are not included. How to push new links to Baidu in real time

Source: Internet
Author: User
Tags php template

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.

Related Article

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.