How to add WeChat public account function to WordPress plug-in
How to add WeChat public account function to WordPress plug-in
With the rapid development of mobile Internet, WeChat public account has become one of the important tools for marketing and promotion of many enterprises and individuals. one. For users who use WordPress as a website building platform, how to add the WeChat public account function to their plug-ins has become a common requirement. This article will teach you how to add the WeChat public account function to the WordPress plug-in and provide corresponding code examples.
1. Register a WeChat public account developer account
Before you start, you need to register a WeChat public account developer account. Open the official website of the WeChat public platform (https://mp.weixin.qq.com/), click the registration button, fill in the relevant information according to the guidelines and complete the account registration.
2. Obtain the WeChat public account developer certificate
After successful registration, enter the WeChat public account platform developer center and click "Developer Tools" in the left menu to enter. On the "Official Account Settings" page, find the two important credentials "Developer ID" and "Developer Password".
3. Install WordPress plug-in
Install a plug-in that can use custom code functions on your WordPress website, such as the Custom JavaScript plug-in. After installation, go to the "Settings" menu to find the plug-in and click "New Code Snippet".
4. Add the WeChat public account interface code
On the "New Code Snippet" page, enter the code in Code Example 1. Among them, you need to replace [APPID] with the developer ID of your WeChat official account, and replace [APPSECRET] with the developer password of your WeChat official account.
Code Example 1:
function get_wechat_access_token() { $appid = '【APPID】'; $appsecret = '【APPSECRET】'; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret; $response = wp_remote_get( $url ); $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body ); return $data->access_token; } function get_wechat_qrcode() { $access_token = get_wechat_access_token(); $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$access_token; $body = '{ "action_name": "QR_LIMIT_STR_SCENE", "action_info": { "scene": { "scene_str": "wechat" } } }'; $response = wp_remote_post( $url, array( 'body' => $body ) ); $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body ); $ticket = $data->ticket; $qrcode_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode( $ticket ); return $qrcode_url; }
The two functions in Code Example 1 are used to obtain the access_token of the WeChat official account and to generate the permanent QR code link of the WeChat official account. You can modify the code according to actual needs.
5. Call the WeChat official account interface
In the page or article where the WeChat official account QR code needs to be displayed, use the following code to call the WeChat official account interface and display the QR code.
Code example two:
<img src="<?php echo get_wechat_qrcode(); ? alt="How to add WeChat public account function to WordPress plug-in" >" alt="微信公众号二维码">
Insert the above code into the position where you need to display the WeChat official account QR code.
Summary:
Through the code examples provided in this article, you can easily add the WeChat public account function to your WordPress plug-in. Of course, if you have a certain understanding of PHP and WordPress development, you can also expand and optimize the code according to actual needs. I wish you good results in your WordPress plugin development!
The above is the detailed content of How to add WeChat public account function to WordPress plug-in. For more information, please follow other related articles on the PHP Chinese website!

Have you seen the "Error establishing a database connection" error page on your WordPress website? There are several reasons for displaying this message, but it is unattractive and may confuse visitors. Additionally, you won’t realize that your website is closed until you visit the website and see the message. In this article, we will show you how to customize database error pages in WordPress. We will also show you how to set notifications every time your website is closed due to a database error. What is the reason for an error in establishing a database connection? "Error establishing a database connection" is one of the most common WordPress errors.

Did your WordPress post return a 404 error on the site? This error occurs when you have access to WordPress admin areas and blogs, but when you try to open a post, you will see "404 Not Found". In this article, we will show you how to fix WordPress posts that return 404 errors. What causes WordPress posts to return a 404 error? WordPress is a powerful content management system (CMS), but minor changes can sometimes lead to your WordPress

In 2025, choosing the perfect WordPress theme is no longer a priority. The real challenge is choosing a topic that is flexible enough to meet the needs of the current project and adapt to the evolution of future needs. The good news is that you don't have to start from scratch. Whether you are building a website for your customers or expanding your own digital products, the following topics strike the ideal balance between design freedom, technical performance, and long-term reliability. These topics are built by developers who understand the important factors: regular updates, clean code, mobile-first responsive design, and compatibility with tools you already use, such as Elementor, Gutenberg, and WooCommerce. In this review, we have narrowed the scope to 9

Blogs are the ideal platform for people to express their opinions, opinions and opinions online. Many newbies are eager to build their own website but are hesitant to worry about technical barriers or cost issues. However, as the platform continues to evolve to meet the capabilities and needs of beginners, it is now starting to become easier than ever. This article will guide you step by step how to build a WordPress blog, from theme selection to using plugins to improve security and performance, helping you create your own website easily. Choose a blog topic and direction Before purchasing a domain name or registering a host, it is best to identify the topics you plan to cover. Personal websites can revolve around travel, cooking, product reviews, music or any hobby that sparks your interests. Focusing on areas you are truly interested in can encourage continuous writing

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Wix is suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool