In the function.php file of the twentyeleven the setup function checks to see whether it exists before running it:

if (!function_exists('twentyelevent_setup')):
function twentyelevent_setup() {
... Setup code ...

add_action( 'after_setup_theme', 'twentyeleven_setup' );

However, in twentytwelve, it is not set up like this (it does not check if the function exists). My question is: what is the point of this design pattern? Does function_exists just check whether the function has been defined (which it is on the next line?) or does it do something else? Why does the new theme not include it?


That twentyeleven_setup function, and others like it, are pluggable - meaning that they can be overridden by a child theme. The child theme's version of a function with that same name will be parsed first, so the parent theme's version will not be run at all.

In TwentyTwelve some functions are not pluggable, but instead are attached to hooks. By attaching alternative functions to those same hooks in a child theme, you can override the parent theme function's internal logic, without rebuilding the whole function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.