WordPress Code Snippets Plugin Tutorial – Easy Custom Functions and Shortcodes

Code Snippets is an easy, clean and simple way to run code snippets on your site. It removes the need to add custom snippets to your theme’s functions.php file.

You can install the plugin from the WordPress Dashboard.

Once you activate the plugin, a new Snippets section will become available. It will contain some sample snippets that you can inspect and adapt.

Code Snippets WordPress Plugin screenshot: All Snippets screen.

Let’s add a new code snippet that will disable Block Based Widgets in favor of classic widgets.

function ilovewp_classic_widgets() {
	remove_theme_support( 'widgets-block-editor' );
add_action( 'after_setup_theme', 'ilovewp_classic_widgets' );

Add a new snippet and give it a clear title for the future you.

Make sure to have the Functions (PHP) tab active. Add your PHP code, select when you want to run it and click on Save Changes and Activate.

When I open the Widgets page, I see the traditional Widgets screen.

If I disable the snippet, I see the new Block Based Widgets screen.

Let’s take another example. I will create a code snippet that will display some static content. For example a simple call to action with a heading and a paragraph.

After you have saved the snippet, copy the shortcode and paste it where you need it.

If you ever need to disable your shortcode snippets, they will disappear only in the front-end. You will still be able to see them in the back-end.

Allow me a quick side-note. Before you start creating shortcodes for every bit of reusable content, I recommend that you check out my Guide to Reusable Blocks. Though not exactly the same, in some cases Reusable Blocks may be a better alternative to shortcodes.

The plugin has a Settings page with some options, though all default values should be fine for most users.

I took some time to look through the plugin’s ratings and support threads on wordpress.org. I noticed that some negative feedback is completely undeserved.

There are cases when users have the wrong expectations or are trying to do something that is not in this plugin’s scope.

Either way, I highly recommend that you check out the Code Snippets Documentation page.

There are many useful tips, such as detailed instructions on how to add the tracking code for Google Analytics, Facebook Pixel and Microsoft Clarity.

Thank you for watching.

Previous Post

Manage 404 Errors and URL Redirections in WordPress with this free plugin

Next Post

How to Reset a WordPress Website with the WP Reset Plugin

Be the first to comment

Leave a Reply or Comment

Your email address will not be published. Required fields are marked *