Rewriting pluggable functions

Another way to modify the theme is to override theme functions in the child theme. In order to be able to override a function from the parent theme, this function has to be pluggable.

Pluggable Functions

A function is pluggable when it’s wrapped with a function_exists if condition. That allows to define a function with the same name in the child theme functions.php which will then be used instead of the function in the parent theme.

Code of a pluggable function:

if ( ! function_exists( 'themename_register_sidebars' ) ):
function themename_register_sidebars() { 


Override pluggable functions

In case you want to override a pluggable function, you just have to copy the original function without the if-condition to the functions.php of your child theme. Then you can alter the function to your needs.

Let’s stick with the pluggable themename_register_sidebars() function from above, which does register all widget areas in the theme. Imagine you don’t want all these various widget areas and just need one simple sidebar area.

Then you can override the default function from the parent theme and completely register your own widget areas.

Example Code:

function themename_register_sidebars() { 
	// Register Sidebar
	register_sidebar(array('name' => __('Sidebar', 'themename'), 'id' => 'sidebar'));

Please note that the default function in the parent theme isn’t called at all, which means also that all default widget areas from the theme are gone.