Home > CMS Tutorial > WordPress > body text

Solve the problem of manually adding custom code again after upgrading WordPress theme

藏色散人
Release: 2020-11-24 15:12:04
forward
2425 people have browsed it

The following WordPress Tutorial column will introduce to you how to solve the problem of manually adding custom code again after upgrading the WordPress theme. I hope it will be helpful to friends who need it. Helped!

Solve the problem of manually adding custom code again after upgrading WordPress theme

Everyone who often messes with themes knows that adding code to the theme function template functions.php can increase the modification function, but it is troublesome to add these codes again after upgrading the theme. , here is a small method to avoid the trouble of repeated operations.

Some children may think of making a sub-theme and adding custom code. The method in this article is much simpler than making a sub-theme.

The principle is to make a plug-in yourself, add custom code to it and enable it.

You might think, wow! I don’t know how to make a plug-in. It’s a bit complicated. It’s actually very simple. Create a new PHP file and add the following code to it:

<?php
/*
Plugin Name: 自定义模板函数
Plugin URI: https://zmingcx.com
Description: 免除升级主题手动添加自定义代码的烦恼
Author: 知更鸟
Version: 1.0
*/
// 将之前主题函数模板functions.php中的自定义代码加在此行下面就可以了,比如在前端加一个提示对话框:
function plugins_tips() {
echo &#39;<script>alert("您已成功制作了第一个WordPress插件!");</script>&#39;;
}
 
add_action( &#39;wp_footer&#39;, &#39;plugins_tips&#39; );
Copy after login

When saving the file, you need to save the encoding as UTF-8 without BOM (no signature). Otherwise, garbled characters will be displayed. Then upload it to the wp-content\plugins plug-in directory and enable it on the WP background plug-in page.

Refreshing the front-end page will display a prompt dialog box, indicating that your first plug-in has been successfully created.

Making custom code into a plug-in has the same effect as adding it to the theme function template functions.php, once and for all.

The above is the detailed content of Solve the problem of manually adding custom code again after upgrading WordPress theme. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!