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

(avery) #1

CHAPTER 8 • Plugins or functions.php? 217


include any cool functions.php features you’ve become reliant on — in your parent theme and
the design stuff and minor changes in the child theme you’re using.


This means that whenever you need to relaunch your site with new modern looks, you can
just create a new child theme without losing any of the functionality. No copying and pasting
of functions.php code, as that all sits in the parent’s functions.php.


You can read more about child themes in Chapter 5, “The Child Theme Concept.”


THE BEST OF BOTH WORLDS:


A FUNCTIONALITY PLUGIN


A functionality plugin is the best of both worlds. The idea is to take the parts of your theme’s
functions.php file that need to be available even after you switch themes and stick them in a
plugin instead. This would include shortcodes (obviously) but also declarations for custom
taxonomies and custom post types because neither of these are really theme specific; you
wouldn’t want your custom taxonomies to disappear from the admin area just because you
switch themes, right?


Things you wouldn’t want in a functionality plugin would include (but not be limited to)
sidebars and menus because those all depend on how the theme is built and designed. The
same goes for feature images, header images, whether the theme supports a custom
background, and such. These things are theme specific.


CREATE YOUR OWN FUNCTIONALITY PLUGIN


Creating a functionality plugin is simple. Because the code in functions.php is plugin-ready
by itself, all you need to do is create a plugin and then add the parts from your theme’s
functions.php file that you want to store in the plugin instead. So why not get started on
creating your own functionality plugin? Here’s the beginning of smashing-functionality.php,
the plugin file that will host all the functionality you want to put in it:


<?php
/
Plugin Name: Smashing Functionality, Baby!
Description: This plugin keeps my features portable.
Version: 1.0
Author: Thord Daniel Hedengren
Author URI: http://tdh.me
/
?>


You probably recognize this; it’s a simple plugin head. The Plugin URI part is cut out because
frankly there’s no need to have that when this is just something you’ll do to keep your features
portable between themes. You could add the license information as well, but I’ll omit that here
for the sake of keeping things simple.

Free download pdf