In this article we will show you the right way to customize WordPress and keep your site up-to-date without losing your customizations.
Firstly, please do not customize WordPress core files. This will cause issues for other plugins, themes or even the general workings of WordPress.
Why Do I Need To Customize WordPress
Websites needs are dependent on the business/owner’s needs. WordPress works great out of the box but sometimes you just need that little extra functionality that may not be solved by a plugin. (If there is no plugin available for this, it may be a good idea to create one and release it to the public. A lot of our WordPress plugins are created because of this reason).
Why Not To Add Custom Code To Functions.php
A lot of sites will mention to “Add this code to your theme’s functions.php file”. This is not a bad practice if you add this to a child theme’s functions.php file. If you add custom code to your theme’s functions.php file, it will work but as soon as you update your WordPress theme it will remove this custom code and revert the functions.php file back to default. A child theme does solve this, but we’ve got a better way of doing this.
The Right Way To Customize WordPress
The best way to customize WordPress is to create a custom WordPress plugin. I’m sure some of you thinking, “What! that’s crazy. I don’t know how to create a plugin!”. Well some good news for you, it’s actually super easy. If you can create a .txt file, you can create a plugin. You may take similar steps to create a WordPress plugin:
- Create a folder on your desktop and name it
my-plugin
. You may name it anything you wish, but be sure to keep it relative to what the plugin does and make sure that dashes are used instead of spaces. For example, “My Awesome Plugin” folder name should be “my-awesome-plugin”. - Open this folder with Sublime Text or Atom. I preferably use Sublime Text but you can use any text editor you are familiar with.
- Create a new file called
my-plugin.php
. With WordPress plugins a .php file that has the same name as the plugin’s folder should always run first automatically when the plugin is activated. - Inside your
my-plugin.php
add the following code:
I Don’t Plan On Having A Lot Of Custom Code
If you don’t plan on having a lot of custom code running on your WordPress site and you would only need a couple of custom functions then using the Code Snippets plugin should be sufficient for your needs. This allows you to add code to your WordPress site directly from your WordPress dashboard.
Why A Custom WordPress Plugin
The changes you would want to do within WordPress should work with hooks. So there should be no need to customize the WordPress core files and a custom WordPress plugin should be enough. Not only will a custom plugin allow you to keep your theme and other plugins up-to-date for security purposes, your custom WordPress plugin will also be able to organize your custom code neatly for future developers to jump right in easily!
Photo by Sweet Ice Cream Photography on Unsplash