A Guide to Overriding Parent Theme Functions in Your Child Theme

If you've had any experience working with parent and child themes in WordPress, you'll know that the template files in your child theme override those in your parent theme. For example, if your parent theme has a page.php file and you create a new one in your child theme, WordPress will use the one in the child theme when displaying pages. You might think that functions would work in the same way: create a new function in your child theme's functions.php file with the same name as one in the parent theme, and it'll take precedence. Unfortunately, it isn't as simple as this. In...

How to Include and Require Files and Templates in WordPress

When it comes to PHP, a lot of developers love the language, a lot of the developers hate the language, and a lot of developers generally just use it to get their work done. For what it's worth, I'm of the latter camp. I think PHP is fine. Like anything, it's not without its problems, but I enjoy working with it well enough and see it as a way to get work done versus a pie-in-the-sky language for some type of development utopia. Some of the things that developers love about PHP—its features and flexibilities—are the very things that often...

Generate WordPress theme templates with Underscores Components

You might already know about Underscores, often abbreviated as _s, which is a popular starter theme for WordPress. This is a big project maintained by Automattic which is the company operating WordPress. Recently they created another tool called Components. This is a free online theme generator built on WordPress with custom blueprints made for portfolios, business sites, and different blog themes from standard blogs to magazines. Components is completely free to use and it’s one of the most powerful generators on the web. Why start a new theme from scratch when you can work with the proven Underscores framework? Each...

How to Override Parent Theme Functions in WordPress

If you are a budding WordPress theme developer there is one thing you will have to end up knowing sooner or later. That is, how to override parent theme functions in WordPress. The reason you would want to do this is to be able to alter some or most of the behavior of a parent theme while retaining other features that are inherited into your child theme. With this WordPress feature, three main parts of the parent theme can be manipulated. They are the templates, the main CSS stylesheet, and the functions. 1. The templates: These are replaced by those in the child theme if...

Prefix all the things

When building WordPress themes, there’s a rule that sits at the top of the list of rules. It’s something all developers should do out of habit, not as an afterthought. Prefix everything. What does it mean to prefix something? Basically, when you create custom functions, classes, and other items in the global namespace, it needs to be unique so that it doesn’t conflict with WordPress, plugins, or other scripts. Therefore, you add a prefix that’s unique to your theme name. If everyone follows this simple rule, it’s rare to see any conflicts. Like rare on the level of seeing a...