Chapter 8: Plugins or functions.php?

WordPress themes and plugins typically work separately from each other, coming together only when it comes to implementing features. This cooperation is usually managed by having the correct widget areas available in the theme’s template files, so the user can drop the plugin’s widget where it should be, or by actually putting plugin PHP code snippets into the theme. Sometimes the plugins will output or activate the functionality by use of the WordPress hooks, which in essence means that the theme only has to comply with WordPress to trigger the plugins. It is all pretty straightforward.

However, there is one case in which themes and plugins collide, and that’s when the functions.php file comes into play. The theme file can do more or less anything a plugin can, which means that it can be an optional solution for a publisher that normally would require a plugin. It also means that functions.php can clash with plugins, if not used with caution.

This chapter explains when you should use a plugin and when to use functions.php instead.

When to Use a Plugin

When opting for the plugin solution over the functions.php option, or comparing the use of a plugin with a custom hack in the theme, you need to consider the following questions:

Is the plugin really needed?

Does the plugin extend WordPress functionality in a way that is either too complicated or so standalone that it really isn’t an option to try and do the same thing in the theme files? ...

Get Smashing WordPress: Beyond the Blog, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.