How best to add code to your functions.php file

How many times have you seen a WordPress tutorial where you’re instructed to add a snippet of code to your functions.php file in order to add new functionality to your site? I’m sure we’re guilty of a few. The best practice is to create your own functionality plugin, instead of loading up your functions.php file with a ton of code.

One of the most important reasons for not doing this is to help you during upgrades and troubleshooting. If your site’s functions are broken up into a separate plugin, it will be easier to turn it on or off while trying to track down a problem or incompatibility. It’s much more difficult if all of those functions are loaded via your theme’s functions.php.

That’s where the new Functionality plugin can make your life easier. It automates the creation of a separate functionality plugin for code that you might normally add into functions.php. It gives you an easy way to keep all of those functions separate.

Quick access to your new functions file is available via the ‘Edit Functions’ menu

Install and activate the plugin and you’ll see a new Edit Functions menu item under the plugins menu. Now you can use the built-in WordPress file editor to quickly edit your functionality plugin.

Advantages of Using the Functionality Plugin:

    Makes it easier to troubleshoot a site without having to turn off your theme

  • Your functions are not tied to your theme, so they will not be affected by theme upgrades
  • Your functions are not affected or deactivated when you switch themes because they are separate from your theme

The bottom line is that it just doesn’t make sense to throw a bunch of extra code into your WordPress theme. Keeping those separate will make site maintenance and updates easier in the long run.

What do you think: Is it better to just add code directly than to add another plugin to your site or is it cleaner to implement upgrades when you don’t add code to your function.php file?

Embedded Link

Automate the Creation of a WordPress Functionality Plugin – WPMU.org

Google+: View post on Google+

One response to “How best to add code to your functions.php file”