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

(avery) #1

CHAPTER 8 • Plugins or functions.php? 219


THE IMPORTANCE OF PORTABILITY


I’ve already touched on portability several times in this chapter, but it is very important, so I’ll
devote some more time to the need for it. I’m talking about making features continue to work
even after you have switched themes, which you can easily achieve by using a functionality
plugin rather than filling your functions.php file with a ton of features.


If any of the following features should continue to function even after you switch themes, they
need to be portable and hence should reside in a plugin rather than in a theme’s functions.php file:


◾ Custom post types
◾ Custom taxonomies
◾ Anything involving shortcodes
◾ Admin customizations

Not all of these should always be in a functionality plugin, but they should be most of the
time. Perhaps your admin customizations, such as hiding various boxes and features for
the end user, are directly tied to your current theme’s needs; then those customizations
would be useless when you activate a new theme.


Custom post types and custom taxonomies are usually global features that will be just as
important when you swap themes. After all, you will probably want to continue to work with
the content in your custom post types and keep using the terms from your custom
taxonomies even after you have switched themes, right?


Make sure that features not directly tied to a specific theme can make the transition across
themes. Doing so means using plugins, not the theme’s functions.php file, to avoid a lot of
unnecessary copying and pasting.


PLANNING FOR EXTENDED FUNCTIONALITY IN


YOUR WORDPRESS SITE


Whenever you feel the need to extend the WordPress functionality on a project, you will have
to figure out whether you can tweak the theme to pull off your ideas or if you need to develop
a plugin. More often than not, when stepping outside of the typical flow of content, it is a
mixture of both, and that’s okay. The important thing is that there are solid ideas behind the
choices being made. The obvious questions are


◾ Do I need a plugin for feature X?
◾ Is it possible to extend feature X without completely overwriting it with new
functionality?
◾ Will feature X work if/when the project gets a new theme?
◾ Will feature X perhaps become an issue when WordPress is updated?
◾ How will feature X integrate with the theme and other plugins/features?
Free download pdf