O'Reilly logo

Smashing WordPress: Beyond the Blog, 4th Edition by Thord Hedengren

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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?

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required