Learn with this tutorial how to create a plugin where you can add your own WordPress functions, not related to the child theme, through code.
Do you already have a few snippets that you like to use in most websites you create?
Then I invite you to use the same strategy as me: put them all together in a functionality plugin.
This has 2 big advantages over adding them individually to functions.php:
- You avoid overloading the functions.php file.
- The code is executed even if you change the child theme.
As you can imagine, the ideal is to add functions that are not directly related to a specific Genesis child theme, but more general.
Here we go:
Snippet to create a WordPress functionality plugin
Generate a file called, for example, “cg-functions.php” with the following code snippet and put it inside a folder with the same name (in this case it would be “cg-functions”).
This is the basic header of the plugin where you introduce its basic information (name, description…), as you did when you created the CPT plugin by code.
After the header you can add all the snippets you usually use.
As I said at the beginning, it’s appropriate to introduce functions that don’t depend on the theme you’re using.
However, if you always work with Genesis Framework, you can add certain actions that you always want to be executed regardless of the child theme. For example, remove Genesis design snippets with multiple sidebars.
When you finish adding all the functions, place the folder in /wp-content/plugins/. It will appear as another plugin in the WordPress panel and you can activate it from there (like any other).
Just like that. You already have your custom plugin.
You can insert new snippets you see in this website or remove those you no longer want to use.
Have you seen how easy it is to create your custom plugin with the functions you usually use when developing or modifying a website?
The advantage over adding them in the funtions.php file is that the code will continue to run even if you change the child theme.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉