When working with a child theme, you may need to remove something from the Express 2 parent theme.
So you want to remove an action added by the theme?
You can do it, and it’s quite easy!
<?php remove_action( $tag, $function_to_remove, $priority ); ?>
We still need to consider one thing when working in the child theme. WordPress loads child theme functions.php earlier than the parent theme. If we just remove the action right away, it will be added by the parent later, regardless.
We need to make our removal happen after the parent has added the action. You could for example use the hook ‘init’, which fires after WordPress has finished loading, but before any headers are sent. (Or any other appropriate hook that is fired later than the action you want to remove).
<?php add_action('init', function(){ remove_action('express_top_modules', 'sircontheme_top_module', 10); }); ?>
Use case: You’re working in a child theme, and some of your changes has made one or more theme settings invalid or broken. You need to make sure the end user never gets to use this settings, as they may get confused.
In Express 2, we have two settingspages: Theme Settings (also used in Customizer), and Theme Advanced settings. Different ID’s make them unique.
SIRCONTHEME_SETTINGSPAGE_ID = ‘sircon_meta’
SIRCONTHEME_SETTINGSPAGE_ADVANCED = ‘sircon_advanced’
When not given an ID, the function will use the regular theme settings ID.
<?php unset_sircontheme_settings_field($fieldName, $id = SIRCONTHEME_SETTINGSPAGE_ID)?>
As with removal of an action, this function also has to run after the setting has been added – if not, it will be added later by the parent.
Example usage: Unsetting regular theme setting ‘frontpage-output’
add_action('init', function(){ unset_sircontheme_settings_field('frontpage-output'); });
Remember to add the settingspage ID as a second parameter when removing a setting from the advanced settingspage.
Head over to WordPress codex for function reference: https://codex.wordpress.org/Function_Reference/unregister_sidebar