This post serves as a repository for all of the items I discussed during my 2014 WordCamp Tampa talk called “Putting things where they belong: child themes and functionality plugins“.
In my talk, I went through how to set up a child theme and a functionality plugin for your site, so that you can make changes to your site in the correct manner, without putting your edits, or the rest of your site at risk.
If you’ve already seen the talk and just need the templates, here’s a link to them for your convenience. The rest of you, read on and the download links will be available again further down the article.
The different types of change
I outlined three different types of changes that you might want to make to your site:
- The first type is style changes. This changes the appearance of certain elements by modifying their font, color, margin, padding, size etc. These types of change are CSS changes, and belong in your child theme’s stylesheet.
- The second type is layout changes. This changes what elements of your site appear in what locations. For example, it determines whether the front page should use the site title or a logo, where the menu should be, and what information should go in the footer. These types of changes are done by adding layout files to your child theme.
- The third type of change is functionality changes. These change how your site operates. Examples of such changes might includes registering a custom post type, or adding tracking codes (like Google Analytics) to each page. These types of changes may belong in your child theme or in a functionality plugin.
The first two are cut and dry: they belong in your child theme. The third one is a little less sure. Why the uncertainty? This can be answered by asking the following question of each functionality change you want to make:
Will this change still apply when I change themes?
If the functionality change applies strictly to your theme, it will belong in the functions.php file in your child theme. If you’re going to want this change to persist after you change your theme in a few years (or next week), it belongs in your functionality plugin. Here’s some examples to help you decipher the difference:
- You want to add a new menu to the footer in your WordPress. You need to register the new menu using register_nav_menu(), but where does it go? Because this one is tied to the theme, it belongs in functions.php (your child theme). Once you change your theme, the appearance is going to change, and your menus will move all over again, so this function will no longer apply at that point.
- You want to register a new custom post type, which you’ll do using the register_post_type() function. This one belongs in your functionality plugin. After you switch themes, you’re not going to want to lose this content, so by keeping the function in your functionality plugin, it will still be available after you change themes.
- You want to add your Google Analytics tracking code to the <head> of each page. Again, because you’re going to want to continue tracking your users after you change themes, this one belongs in your functionality plugin.
- You want to register a new sidebar (using register_sidebar()) which will appear on certain pages. Because this affects the appearance of the site and how the theme displays your content, this one belongs in your child theme’s functions.php.
Now that you know what belongs where, let’s create a child theme and a functionality plugin.