Overriding core functions in child theme

Is it good practice to use children functions.php to override parent core functions?

Example in Storefront theme :

Core function

if ( ! function_exists( 'storefront_primary_navigation_wrapper' ) ) {
    /**
     * The primary navigation wrapper
     */
    function storefront_primary_navigation_wrapper() {
        echo '<div class="storefront-primary-navigation"><div class="col-full">';
    }
}

children functions.php

  function storefront_primary_navigation_wrapper() {
      // modified content;
  }

1 Answer
1

Basically, that is what Child Themes are meant to be, you have the need to modify the theme, but you shouldn’t do it directly on the theme since the updates will mess you up, instead, you do all your customizations and new features on your Child Theme so you will be alright.

From codex.

If you modify a theme directly and it is updated, then your
modifications may be lost. By using a child theme you will ensure that
your modifications are preserved.

It’s a good practice, to sum up.

Leave a Comment