网站百度分享代码突然没有了不显示了?解决WordPress百度分享无效问题
最近维护网站过程中突然发现百度分享没有了,经过排查发现,是因为网站开启了SSL证书而导致的。
百度分享无效问题的原因:
网站百度分享代码突然没有了不显示了,百度分享无效问题的主要原因在于,百度分享代码不支持https。百度分享代码运用的链接方式是通过代码调用百度远程的CDN库,但是百度服务器并不支持https格式。
百度分享无效问题的解决方法:
解决百度分享不支持HTTPS方法其实很简单,只需要先把百度分享代码本地化。下面告诉大家如何解决:
一、需要将百度CDN库中分享的代码文件下载下来,然后将这些文件本地化。代码已经下载下来整理好了,大家只需要直接下载,解压到自己的电脑,然后将static整个文件夹上传到网站根目录就行。(百度分享代码:http://www.aiyanxia.com/wp-content/uploads/2024/09/baidusharehttps.zip)
二、再把“http://bdimg.share.baidu.com/”替换成“你自己网站的域名”。wordpress主题中,百度分享代码一般都放在了footer.php中。
修改前的代码:
<?php if ( is_single() && (get_theme_mod('single-share-on', true) == true) ) : ?> <?php $baidu_share_url = ""; if ( function_exists( 'zimeiti_1_check_https' ) ) { if (zimeiti_1_check_https()) { $baidu_share_url = ""; } else { $baidu_share_url = "http://bdimg.share.baidu.com"; } } ?> <script> window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='<?php echo $baidu_share_url; ?>/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; </script> <?php endif; ?>
修改后的代码:
<?php if ( is_single() && (get_theme_mod('single-share-on', true) == true) ) : ?> <script> window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='https://ai.aiyanxia.com//static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; </script> <?php endif; ?>