Chapter 8. PLUGINS AND FUNCTIONS.PHP

WordPress themes and plugins usually work pretty much by themselves, coming together only when it comes to implementing features. This is usually managed by having the correct widget areas available in the theme's template files, so that the user can drop the plugin's widget where it should be, or by actually putting plugin PHP code snippets into the theme. And 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 where themes and plugins collide, and that's when functions.php 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 used without caution.

This chapter discusses when to use what solution, and why.

When to Use a Plugin

In short, there is a good rule for when to use a plugin: everything that extends WordPress functionality should be a plugin.

This means that if you add something to WordPress that you wouldn't be able to do otherwise, you should do the actual addition with a plugin. What that addition of functionality actually is would of course depend on what needs you have, but anything from added data management to integration with third-party apps would qualify. ...

Get Smashing WordPress: Beyond The Blog 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.