Why does the method above work in some themes and not others?
That is because those themes have a function_exists
check before they define a function. Taking a function from the Twenty Thirteen theme as an example it has the following code in its functions.php file.
if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
/**
* Display navigation to next/previous set of posts when applicable.
*
* @since Twenty Thirteen 1.0
*
* @return void
*/
function twentythirteen_paging_nav() {
//Some code here
}
endif;
Now if you wanted to override this function all you have to do is to define this function in your Child Theme’s functions.php file. So the parent theme will check if this function exists and won’t run this block at all.
From the functions.php file of Twenty Thirteen.
When using a child theme (see https://codex.www.ads-software.com/Theme_Development and https://codex.www.ads-software.com/Child_Themes), you can override certain functions (those wrapped in a function_exists() call) by defining them first in your child theme’s functions.php file.
Now for your other questions
What does the author mean by “Child themes should do their setup on the ‘after_setup_theme’ hook with a priority of 11 if they want to override parent theme features”?
Look at this line of your functions.php (parent theme)
add_action( 'after_setup_theme', 'neutro_theme_setup' );
This is where a function called neutro_theme_setup
is hooked. This function loads several stylesheets, scripts, theme features etc.
So inside this function we have this line
add_action('wp_head', 'neutro_customizer_css');
which loads a particular CSS file inside the <head>
.
So if you wanted to remove it using a child theme this is what you’d have in the functions.php (child theme).
add_action( 'after_setup_theme', 'my_theme_setup', 11 );
function my_theme_setup()
{
remove_action('wp_head', 'neutro_customizer_css');
}
Notice the third parameter of add_action
11. This makes the my_theme_setup
function execute after neutro_theme_setup
. So the parent theme will add this CSS while your child theme will remove it.
Also the theme author says
Child themes should do their setup on the ‘after_setup_theme’ hook with a priority of 11 if they want to override parent theme features.
Notice the word “features” here, the author didn’t say that “functions” can be overridden.
More info
https://codex.www.ads-software.com/Function_Reference/remove_action
https://codex.www.ads-software.com/Function_Reference/add_action