O'Reilly logo

Smashing WordPress: Beyond The Blog by Thord Daniel 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 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. ...

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