Creating extendable WordPress theme


I think that every decent WordPress developer knows that the best way to modify a WordPress theme you don’t own is by creating a child theme, where you create a new style.css where you specify in its header comments which existing theme you are applying changes to.

Funny thing is that for a long time I thought only the appearance can be tweaked via the child theme. Ok, I discovered that you can override certain functions in functions.php from the parent if they are checked for existence (function_exists) – child theme functions are defined before parent functions so if parent detects a certain function has already been defined, then it doesn’t override it.

Until recently when I reread the docs about child themes I learned that for any other file than functions.php if you define your own, say header.php, then this file will be used and not parent’s. My mind was kinda blown away. Because that pretty much means you can tweak/extend almost all aspects of a parent theme.

Since discovering this feature I was able to tweak twentytwelve theme by moving post’s date and edit link under its title and removing post’s entry footer on an index page (by creating my own content.php). I also supplied my own header.php where I replaced main navigation with social one and moved custom header behind site’s title and description (inspired by Independent publisher theme).

So to create extendable WordPress theme, apart from using function_exists in functions.php, also refactor theme in as many files as possible and where it makes sense so child themes can override them.