Home>Article>CMS Tutorial> Solve the problem of manually adding custom code again after upgrading WordPress theme

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

藏色散人
藏色散人 forward
2020-11-24 15:12:04 2407browse

The followingWordPress Tutorialcolumn will introduce to you how to solve the problem of manually adding custom code again after upgrading theWordPresstheme. 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:

alert("您已成功制作了第一个WordPress插件!");'; } add_action( 'wp_footer', 'plugins_tips' );

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!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete