Home >Backend Development >PHP Tutorial >Discuz WeChat sharing problem solutions
Discuz WeChat sharing problem solution
When using the Discuz forum system to develop a website, we often encounter WeChat sharing problems. Sometimes the shared content is not displayed properly. , even unable to share normally. This article will introduce how to solve common problems with Discuz WeChat sharing, and provide specific code examples for your reference.
1. Problem description
2. Solution to the problem
Global-> Basic settings- in the Discuz backend management center > In site information, set the website header information to ensure that the page has the correct title, description and keywords. This information will be automatically recognized and displayed when shared to WeChat.
Sample code:
<meta name="description" content="网站描述"> <meta name="keywords" content="关键词"> <title>网站标题</title>
In the application of Discuz background management center-> WeChat-> Public account settings , fill in the information related to the WeChat official account, including the official account AppID, AppSecret, etc. Fill in the secure domain name of the website in the "JS Interface Secure Domain Name" column to ensure that WeChat can read the web page content normally.
In the page that needs to be shared, add relevant information shared by WeChat, including title, description and image link. The specific code examples are as follows:
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script> wx.ready(function () { wx.onMenuShareAppMessage({ title: '分享标题', desc: '分享描述', link: '分享链接', imgUrl: '分享图片链接', success: function() { // 分享成功的回调 }, cancel: function() { // 取消分享的回调 } }); }); </script>
In the above code, we introduced WeChat’s JS-SDK library and set the shared title, description, link and image link. Make sure that this information is obtained dynamically so that it can be displayed correctly when shared on different pages.
After the setting is completed, you can open the web debugging tool to check whether the meta information of the page source code is correct, and share it in WeChat for testing , check whether the shared effect meets expectations.
3. Summary
Through the above steps and code examples, we can solve the WeChat sharing problems encountered when using Discuz. Correctly setting the website header information, WeChat sharing configuration and sharing link can ensure that the title, description and pictures can be displayed normally when sharing to WeChat. At the same time, timely debugging and testing are also key steps to solve problems and ensure the normal operation of the sharing function.
I hope the above content will be helpful to everyone who encounters WeChat sharing problems when using Discuz to develop websites, and can successfully solve related problems. I hope everyone’s website can be successfully shared on the WeChat platform and gain more traffic and attention.
The above is the detailed content of Discuz WeChat sharing problem solutions. For more information, please follow other related articles on the PHP Chinese website!