The purpose of a creating a child theme is to modify the features of the parent theme. That said, I feel that the easiest feature to modify or extend, is the styling provided by the parent theme. Of course, if there are a sufficient number of actions and filters provided, we can comfortably tweak several functions of the parent theme.
I was working on a theme modification project, where I had to change the behaviour of a shortcode in the theme. I had already created a child theme, and all I had to do, was to add the following code in my child theme’s functions.php.
[space]
Overriding Parent Shortcode Functions in Child Theme
[pre]add_action(‘init’, ‘remove_parent_theme_shortcodes’);
function remove_parent_theme_shortcodes() {
// remove shortcode from parent theme
// shortcode_name should be the name of the shortcode you want to modify
remove_shortcode( ‘shortcode_name’ );
// add the same shortcode in child theme with our own function
// note to self: think of a better example function name
add_shortcode( ‘shortcode_name’, ‘wdm_child_theme_shortcode_name’ );
}
function wdm_child_theme_shortcode_name( $atts ) {
// write your shortcode function here.
}[/pre]
[space]
We Provide Theme Customization
Contact us to extend your theme’s functionality or to improve User Interface Experience
[space]
Well, in case your shortcode function is completely different than the parent theme’s function, this method should work perfectly. But if you were modifying the parent theme function and writing the code here, be sure to check any changes in the original function when the parent theme is updated.