Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

214 PART III • Using Plugins with WordPress


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?
◾ Does the plugin need to work outside of the chosen theme?

A positive answer to all these means that you should go ahead with your plugin.

EXTENDING FUNCTIONALITY WITH PLUGINS
In short, there is a good basic rule as to when to use a plugin: Everything that extends
WordPress functionality should be a plugin. This means that if you add something to Word-
Press that you wouldn’t be able to do otherwise, you should do the actual addition with a
plugin. Examples of such functionality range from added data management to integration
with third-party apps.

However, there’s a big gray area here. A lot of plugins are actually mimicking WordPress and
its loop, such as recent post listings and similar solutions that exist so that the user won’t have
to create a lot of custom loops within the theme’s template files. The plugins can handle that
for you, and they do it in a more user-friendly fashion, with options pages that set up the
custom loop for you and widgets that let you drop them wherever you like. Compare that to
having to actually write the loop code and put it in your theme file to be outputted where you
want to. That may not seem like a big deal if you are a PHP expert, but for most WordPress
users, it is a real hassle. In such cases, plugins aren’t really extending functionality but
enabling users who might not otherwise be able to access that functionality.

Custom fields are another example of built-in functionality that might be better handled with
a plugin. Custom fields are great for a lot of things, but at the same time, they aren’t exactly
easy to use, with a bulky interface and such. A plugin can do the same thing, and in fact use
custom fields, but with a sleeker interface. That can potentially make updating your site easier.

CAUTION: PLUGINS CAN SLOW DOWN YOUR SITE
Nobody likes a slow-loading site, no matter how flashy it is. How fast your site needs to be
depends on the target audience and kind of content being served. After all, intro pages with
movies and sound and whatnot are still fairly common, and they should really not exist unless
there is an audience for them.

No site should be slower than it needs to be, and a sure way to bloat your WordPress site is to
fill it to the brim with plugin-powered functionality. Think about it: Most plugins need to be
initialized to work when the visitor encounters their functionality on the site, and that in turn
can mean anything from running a PHP function (at the very least) to a full-sized loop with
Free download pdf