216 PART III • Using Plugins with WordPress
functionality that they need to be added because you’ll probably need them in the long run.
And although you may think that you just created the perfect theme, sooner or later you’ll
end up switching to the next perfect theme, which means that you’ll have to tackle the loss of
whatever you’ve added to functions.php. True, you can just move the code from the old
theme’s functions.php file to the new one, but why bother with that?
The rule of just putting functionality in functions.php that is unique for the particular theme
is a good one, I think. Examples of such functionality include layout settings (obsolete in
a different theme) and theme option pages that would change slightly depending on how
something is added and/or shown in the theme. Because putting that functionality in
a plugin would make the plugin obsolete when you switch themes, functions.php is
a better choice.
So, plugins are for extending WordPress functionality, and functions.php is for things unique
to the actual theme. That pretty much wraps it up.
THE SHORTCODE DILEMMA
Shortcodes, which you played with a bit in the previous chapter, “Making the Most of Word-
Press Plugins,” might sound like a great idea, and sometimes they are. Far from all end users
will want to write HTML code, and sometimes a shortcode might be warranted. However,
they can be a problem if the code behind them is located in the theme’s functions.php file. Say
that you have a shortcode for a fancy pull quote, called [pull]. The functionality came with
your theme, and you’ve been making your posts looking fine and dandy ever since you
activated the theme. But time flies and your needs change, so you end up getting a new theme.
You activate it, and suddenly all the fancy pull quotes are gone! Instead, you get [pull]
wherever the shortcode usually outputted the pull quote. How come?
It’s quite simple really. Because the code for making the [pull] shortcode work was located
in your old theme’s functions.php and that theme isn’t active anymore, the [pull] shortcode
will be handled as common text. Not too pretty, that.
Luckily, you can solve this problem easily enough. You can copy the [pull] shortcode part
from your old theme’s functions.php to your new theme’s functions.php. An even better
solution is using a child theme’s functions.php, which you’ll get to in a little bit. Another
solution is to create a functionality plugin where you keep all your fancy stuff, which makes it
theme independent. This obviously goes for other features as well, not just shortcodes, but it is
by far the most common problem when switching themes and there are shortcode features
involved. You’ll read about functionality plugins later in this chapter.
SOLVE IT WITH CHILD THEMES
Another way to solve the features problem is to use child themes. Assuming that you’ve created
or found the perfect theme to build on, you can create child themes for the various iterations of
your site. As always when it comes to child themes, keep your core features — which would