A pluggable function is a a function wrapped in a function_exists()
call eg.
<?php if ( ! function_exists( 'my_pluggable_function' ) ) { function my_pluggable_function() { /* Some code goes here */ } } ?>
When using a child theme, you can override pluggable functions by defining them first in your child theme’s functions.php
file. The child theme’s functions.php
file is included before the parent theme’s file, so the child theme functions would be used.
If the functions that are not pluggable are instead attached to a filter or action hook you can replace them using the following method in the child theme’s functions.php
. I have used the example of the widgets_init
action.
- Unhook the parent theme’s widget function (declared in the parent theme’s
functions.php
) from thewidgets_init
action - Create a customized function to register widget areas for the child theme
- Hook our new function to the
widgets_init
action
Again, this code would go in the child theme’s functions.php
with no need to modify the parent theme’s functions.php
.
<?php remove_action( 'widgets_init', 'parenttheme_widgets_init' ); function childtheme_widgets_init() { /* Some code to register widget areas goes here */ } add_action( 'widgets_init', 'childtheme_widgets_init' ); ?>