WordPress pushes new links to Baidu in real time to achieve quick indexing

Source: Internet
Author: User
Tags php template wordpress blog

Careful friends may have found that the Baidu webmaster platform has a link submission option. Baidu provides three methods to push the URL for indexing: active push, automatic push, and sitemap. If WordPress is used as an example, active push can notify Baidu when an article is published, shortening the time for Baidu crawlers to discover new links to the site, so that newly released pages can be indexed by Baidu immediately, in addition, the official statement effectively protects originality (it seems that Baidu still determines whether the article is original based on the indexing time ). Automatic push means that it is pushed to Baidu only when the page is accessed. It is implemented through javascript scripts, and the advantage is that the deployment is simple. Sitemap is a conventional website map mode, which is regularly captured by Baidu.

After the above introduction, we can find that the active push is the best, the automatic push is the second, and the sitemap is the worst. Active push on deployment is the most convenient. The following describes how to submit a new connection in WordPress blog.

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.

<Script>
(Function (){
Var bp = document. createElement ('script ');
Bp. src = '// push.zhanzhang.baidu.com/push.js ';
Var s = document. getElementsByTagName ("script") [0];
S. parentNode. insertBefore (bp, s );
})();
</Script>

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.

 

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.