Debates have raged for ages—and still rage—about how to think about code on a WordPress site. Some people are fast-and-loose types who just want it working quickly as possible. For people in a hurry, the Code Snippets plugin is a quick and effective way to build and manage small quick “WordPress hacks.” While I still think file-system access is a better idea for writing WordPress PHP, I can’t deny the quickness of this (or any) PHP code snippets plugin.
In general, a WordPress snippet will just be a bit of code you’ll get from something like a theme or plugin seller to make their code work more how you’d like. I think it quickly gets unwieldy and confusing when you use too many of these in a plugin like the one we’re covering. But with this plugin’s quick-and-easy error-recover system, I can say I found it hard to really “break” a site. Without further ado…
How to Manage WordPress PHP Code Snippets, the video
Add a PHP Code Snippet to Your WordPress Site
- Install the plugin. To install the Code Snippets plugin, go to the “Plugins > Add New” page in your WordPress site. In the search box, you’ll enter the plugin name “Code Snippets.” “Install” the plugin, and then “Activate” it.
- Go to the page to add a snippet. If you’ve successfully got the “Code Snippets” plugin running, you’ll now have a new menu item in the your left admin sidebar. You’ll see “Snippets” (with a scissors logo) under the typical place you’ll have your “Plugins” menu item. To add a new snippet, select “Add New” in the snippet menu.
- Add the snippet. On the “Add New Snippet” screen, you’ll be able to paste your little PHP snippet. It goes in the big box labelled “Code.” Above that you’ll have space to give the code block a “title” or “name” so that you’ll be able to find it later in the rest of the interface for the plugin. To get your PHP snippet running, you’ll click on the “Save Changes and Activate” plugin in the bottom. (Worth knowing: you can save snippets that themselves aren’t running. That’s what the “Save Changes” button would do for us.)
That’s it. One of the things I like about the Code Snippets plugin is that if you create a fatal PHP error (not as bad as “fatal” implies, but still a problem), you’ll be able to undo that change by simply clicking the “Back” button in your browser. (I show this off in the video ?)
Keep reading the article at WPShout. The article was originally written by David Hayes on 2020-10-08 18:53:25.
The article was hand-picked and curated for you by the Editorial Team of WP Archives.
This article was written by David Hayes and originally published on WPShout.