How does WordPress introduce Baidu Bear's paw number? WP plugin-free code to add bear's paw number tutorial

WordPressHow to introduce Baidu Bear's paw account?

WP plugin-free code to add bear's paw number tutorial

What is Baidu Bear's Paw?What is the bear's paw used for?

Chen WeiliangThis blog post says:What is the use of registering for Bear's Paw and Baijia?

OnChen WeiliangIt seems that the reason why Baidu launched the bear paw number is that Baidu takes advantage of its search engine platform and webmaster resources. It wants to compete with other self-media platforms such as WeChat official account and Toutiao account to seize more market share. Competition is also a good thing. , indicating that there is a future (money way).

However, the entry requirements for Bear's paw are lower than Baidu MIP, so it is very suitable forE-commercepractitioners,new mediaPeople use yo!

Structural transformation of the bear's paw number page

WordPress is also able to use plug-ins to allow the website to implement the structured introduction of Baidu Bear Paws.

but,WP pluginToo many installations may affect the website speed, soChen WeiliangIt is recommended to add code to introduce.

Since WordPress version 2.9, it supports Canonical tags by default (URL normalization tags, which can effectively avoid weight loss caused by multiple URLs), so we can skip the first step and directly add the "JSON_LD data" of the bear paw number.

How does WordPress introduce Baidu Bear's paw number? WP plugin-free code to add bear's paw number tutorial

Add bear's paw number JSON_LD data

The following code is an example of the JSON-LD data of the bear's paw number:

<script type="application/ld+json">
 {
 "@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
 "@id": "https://ziyuan.baidu.com/college/articleinfo?id=1464",
 "appid": "1554494844552021",
 "title": "百度移动搜索落地页体验白皮书——广告篇2.0",
 "images": [
 "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png",
 "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png",
 "https://m.baidu.com/static/index/plus/plus_logo.png"
 ],
 "description": "优质合理的广告作为信息的补充,广受用户喜欢。2017年初百度用户体验部针对用户进行了满意度调研,发现很多恶意低质的广告严重破坏着用户的搜索体验。",
 "pubDate": "2017-06-15T08:00:01",
 "upDate": "2017-06-16T01:02:03",
 "lrDate": "2017-06-17T09:10:11"
 }
 </script>

The official Baidu Bear paw number provides the meaning of the code as follows:

  • @context: Required field, please keep "https://ziyuan.baidu.com/contexts/cambrian.jsonld", if you need to verify the schema of the data, you can replace it with the schema address
  • @id: Required field, the url@id of the current web page: Required field, the url of the current web page
  • appid: Required field, bear's paw ID
  • title: Required field, title, recommended length: within 20 characters
  • images: Optional field, display of structured information of search results, only 0, 1 or 3 images are allowed
  • description: Optional field, content summary: within 120 characters
  • pubDate: Required field, content publishing time

Then we can't modify it one by one. In fact, it is also simple. In the footer.php file of the currently used theme, theAdd the following similar code before, and your APPID can be found in the page modification example of Bear's Paws.

We use the WordPress open source program, and there is no need to modify each page at all.

As long as the code in the footer.php file of the currently enabled WP themeBefore, just add the following code:

<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "<?php the_permalink(); ?>",
"appid": "你的 APPID",
"title": "<?php the_title(); ?>",
"images": ["<?php the_post_thumbnail_url(); ?>"],
"description": "<?php echo wp_trim_words( $post->post_content, 100, '…' ); ?>",
"pubDate": "<?php echo get_the_time('Y-m-d\TH:i:s')?>"
}
</script>
<script src="//msite.baidu.com/sdk/c.js?appid=你的 APPID"></script>

Code meaning:

  • @id= Get current page URL
  • title= current page title
  • images= Featured image of the current page
  • Description= After the first 100 words of the page description, use ...
  • pubDate= page publication time year-month-day TH:hour:minute:second

Please Note

Please be sure to change the above "your APPID" to your own APPID.

Get the bear's paw number APPID and TOKEN

  • Please get your APPID on the API submission page of Bear Paws ▼

Baidu Bear's Paws API Submission Push Interface No. 2

Find the "Push API" and get the appid and token in the API call address:

http://data.zz.baidu.com/urls?appid=你的APPID&token=你的token&type=realtime

Bear's paw API automatic submission

After WordPress has completed the page transformation, the next step is to submit the content to Baidu Bear's paw.

There are 2 ways to submit:

  1. API auto submit
  2. Manual submission

(It is very similar to the previous link submission of Baidu webmaster platform)

If you manually push the content to the bear's paw account every time, it is too troublesome, it is best to add the bear's paw account to automatically submit the code.

We just need to add the following code in the function.php file of the theme:

/**
* 百度熊掌号API自动提交:WordPress免插件自动推送代码
* 文章地址:https://www.chenweiliang.com/cwl-552.html
*/
if(!function_exists('Baidu_XZH_Submit')){
 function Baidu_XZH_Submit($post_ID) {
 //已成功推送的文章不再推送
 if(get_post_meta($post_ID,'BaiduXZHsubmit',true) == 1) return;
 $url = get_permalink($post_ID);
 $api = 'http://data.zz.baidu.com/urls?appid=你的APPID&token=你的TOKEN&type=realtime';
 $request = new WP_Http;
 $result = $request->request( $api , array( 'method' => 'POST', 'body' => $url , 'headers' => 'Content-Type: text/plain') );
 $result = json_decode($result['body'],true);
 //如果推送成功则在文章新增自定义栏目BaiduXZHsubmit,值为1
 if (array_key_exists('success',$result)) {
 add_post_meta($post_ID, 'BaiduXZHsubmit', 1, true);
 }
 }
 add_action('publish_post', 'Baidu_XZH_Submit', 0);
}

Please Note

  • Please be sure to modify "your APPID" and "your TOKEN" in the above code to your own.
  • For the acquisition method, please refer to the above "Obtaining Bear's Paw Number APPID and TOKEN".

Bear's paw online inspection tool

After adding the code, remember to refresh your cache (provided you have the WP cache plugin installed).

Then, please use the online verification tool of Baidu Bear Paws to help you detect whether there is an error in the page code?

Specific location:Page renovation → Online verification tool

Baidu Bear's paw number online verification tool No. 3

What if an error occurs?

  • If there is an error, please check whether the URL that needs to be detected is filled in incorrectly?
  • Remember to add http. If SSL is enabled, add https to the URL.
  • Please correct the errors according to the prompts of the verification tool.

After the verification is successful, the following prompt will appear:

  • Your data passes validation
  • Details
  • The verification is successful, your data conforms to the bear's paw number format standard

After the verification is successful, the following prompt will appear: Your data is successfully verified through the verification details, and your data conforms to the fourth sheet of the bear's paw number format standard

Chen WeiliangThe bear's paw number of the blog is also verified here!

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does WordPress introduce Baidu Bear's paw account? WP plugin-free code to add bear's paw number tutorial", to help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-552.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top