Child Theme Function Override

Hello Colorlib,

I have been playing around the Dazzle WP Theme and I’m madly in love with it! Thank you for an amazing free theme!

I created a child theme to work on customizations which have been working quite well.

I also tried to make a few changes to the slider, specifically to remove the excerpts (because too many lines showed up and essentially covered up the slider image). I found out I could comment out the command that called the excerpts in the inc\extras.php. There was an update my changes (the commenting) was removed.

So here is my question:

How do I apply function changes within my Child Theme to reflect on the Parent Theme? Copying the inc\ folder along with the extras.php file in it and editing that file (like you would for a child theme) didn’t work.

Thank you so much for you time, your help,… and of course such an amazing WP Theme!

Taylor.

@seuntaylor

I see your pain. :slight_smile:

I have wrapped most of the functions in extras.php with

if ( ! function_exists('function_name') ) :

Which means that you can redeclare these functions as WordPress now check if this function exists.

For example you can copy the entire dazzling_call_for_action function from extras.php file to Child Theme functions.php (Not extras.php as it is not part of WordPress default template files) and edit it there.

Here is that function how you should copy it:

if ( ! function_exists( 'dazzling_call_for_action' ) ) :
/**
 * Call for action button & text area
 */
function dazzling_call_for_action() {
  if ( is_front_page() && of_get_option('w2f_cfa_text')!=''){
    echo '<div class="cfa">';
      echo '<div class="container">';
        echo '<div class="col-md-8">';
          echo '<span class="cfa-text">'. of_get_option('w2f_cfa_text').'</span>';
          echo '</div>';
          echo '<div class="col-md-4">';
          echo '<a class="btn btn-lg cfa-button" href="'. of_get_option('w2f_cfa_link'). '">'. of_get_option('w2f_cfa_button'). '</a>';
          echo '</div>';
      echo '</div>';
    echo '</div>';
  } else; {
  //Do nothing
  }
}
endif;

Now you can edit the way you want it and it will be loaded first as Child Theme functions are loaded first and function_exists makes sure that it is not loaded twice and doesn’t throws errors such as “function already declared”

Let me know if this helps.

Whoo!

Yup yup that worked!

These are the steps I followed;

  1. Created an empty functions.php file and placed it in the theme-child folder.
  2. Went to the inc\extras.php file, copied the whole function I needed to alter in the child theme, including the if ( ! function_exists('function_name') ) : and the endif; that existed before and after the function started and ended, respectively.
  3. I pasted the function text I copied from the inc\extras.php into the theme-child\functions.php file I created.
  4. I then altered the function as I wanted to and saved the functions.php file within the theme-child folder.
  5. I then refreshed the page and voila! The changes took effect!
  6. Thank you so much Aigars for your timely and clear response! I hope this helps many other people too!

    Oluseun Taylor.

@seuntaylor

Thank you for posting these detailed steps how you got it done. I hope others will find it useful as well. I will definitely point everyone to this thread users looking to learn more about Child Themes.

Thank you!

Hello.

Im trying to do this for “sparkling_wpsearch” function in extras.php, but is not working. I noticed that function is not wrapped with an if conditional. What can i do to “override” this function?

Thanks!