How to remove a custom action on child theme?

Answer

  1. For removing an action hook use the same action name, callback name and priority that was used to add a action in parent theme.
  2. You should move the function from being defined in index.php to functions.php of the parent theme.
  3. Lastly, you could register the child function using init.

So you end up with something like this:


Parent Theme Code

functions.php

// The function.
add_action( 'mytheme_example_action', 'mytheme_example_function' );
function mytheme_example_function() {
    echo 'Example text on index page.';
}

Child Theme Code

functions.php

// Example 1
add_action( 'init', 'mytheme_remove_parent_function');
function mytheme_remove_parent_function() {
     remove_action( 'mytheme_example_action', 'mytheme_example_function' );
}

Final Notes

Here’s a great tutorial that’ll show you a couple methods of achieving your desired outcome.