Overview of Baidu Link Submission Methods
To submit website link data to the Baidu Search Resource Platform, there are three main methods:
- Active Push (Real-time): The fastest submission method. It is recommended to push newly generated links to Baidu immediately via this method to ensure timely indexing.
- Sitemap Submission: Periodically place website links in a Sitemap file and submit it to Baidu. Baidu will crawl and process the links periodically, but indexing speed is typically slower than active push.
- Manual Submission: Submit a small number of links to Baidu at once, suitable for temporary or supplementary submissions.
According to Baidu's long-term strategy, Active Push (Real-time) is the officially recommended core submission method, effectively improving indexing efficiency.
Implementing Active Push in WordPress Without Plugins
You can automatically push links to Baidu when publishing posts by adding the following code to your current theme's functions.php file, without needing a plugin.
Core Code Implementation
Copy the following code to the end of your theme's functions.php file:
/**
* WordPress integration for Baidu Search Resource Platform Active Push (Real-time)
* @param int $post_id Post ID
* @param WP_Post $post Post object
*/
function push_to_baidu($post_id, $post) {
// 1. Set your push API URL (obtain from Baidu Search Resource Platform)
$api_url = 'https://data.zz.baidu.com/urls?site=YOUR_SITE_DOMAIN&token=YOUR_TOKEN';
// 2. Get the current post's permanent link
$post_url = get_permalink($post_id);
// 3. Get post last modified time, formatted to ISO 8601 for Baidu
$post_modified = get_post_modified_time('c', true, $post_id);
// 4. Construct the XML data for pushing
$xml_data = '<?xml version="1.0" encoding="UTF-8"?>
<urlset>
<url>
<loc><![CDATA[' . $post_url . ']]></loc>
<lastmod>' . $post_modified . '</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>';
// 5. Create HTTP request object and send POST request
$wp_http = new WP_Http();
$response = $wp_http->post($api_url, array(
'body' => $xml_data,
'headers' => array('Content-Type' => 'text/xml')
));
// Optional: Log push response for debugging
// error_log('Baidu Push Response for ' . $post_url . ': ' . print_r($response, true));
}
// 6. Hook to the post publish action
add_action('publish_post', 'push_to_baidu', 10, 2);
Configuration and Usage Instructions
- Obtain API URL: Log in to the Baidu Search Resource Platform, find "Active Push (Real-time)" under "Link Submission," and get your API call URL (containing
siteandtokenparameters). - Modify Code: Replace the value of the
$api_urlvariable in the code above with your own complete API URL. - Activate Code: After saving the
functions.phpfile, WordPress will automatically push the link of each new or updated post to Baidu.
Important Notes
- Security: Always back up your
functions.phpfile before making changes. - Child Theme: If you are using a third-party theme, it is recommended to create and use a child theme and add the code to the child theme's
functions.phpto prevent code loss during theme updates. - Push Limits: Baidu has daily push limits; refer to the platform's latest rules. This code only pushes single posts and is suitable for sites with lower update frequency.
- Error Handling: For production environments, consider adding error handling logic (e.g., checking
$responsestatus) and logging push failures for troubleshooting.
By following these steps, you can implement Baidu Search Resource Platform's active link push functionality for your WordPress site without relying on plugins, helping your content get indexed faster.