• Hi,

    i bought a theme and to not destroy it, i created a child theme.
    now i would like to overwrite some functions of the functions.php file of the parent theme.

    firstly i checked if the parent theme function includes a check before like:

    if (!function_exists('my_function')) {
       ...

    but nothing as such exists so i must firstly remove it and recreate it.

    So i created a functions.php file in my child theme and tried to remove existing function to recreate it in my child theme as following:

    remove_action('showTop' );
    function showTop(){
     ...
    }
    add_action( 'showTop' );

    but it does not remove it from parent functions.php file.

    any idea where is my mistake ?
    thx

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not 100% sure, but I would do this:

    1. copy ‘functions.php’ of the original theme to the folder of the childtheme
    2. empty the ‘functions.php’ of the childtheme.
    3. rewrite the function you want to change

    i bought a theme

    please contact the theme’s developer for support.

    this forum does not support commercial themes; https://codex.www.ads-software.com/Forum_Welcome#Commercial_Products

    in general, you might need to work with ‘after_setup_theme’ and possibly change the priorities.

    example:

    add_action( 'after_setup_theme', 'child_theme_corrections' );
    
    function child_theme_corrections() {
    
    //your 'remove_action' etc codes here//
    
    }
    Thread Starter Alain

    (@alainroger)

    in my case the theme header.php call the function “showTop()” (from functions.php) using the following code:
    <?php showTop() ?>

    so no add_action nowhere.

    what is the best solution ?
    – To remove this function or can i directly change function name in my child theme to another function ?

    in case i add a new function call in the header.php it should be ok AFAIK, no ?

    the theme header.php call the function “showTop()”

    in case i add a new function call in the header.php it should be ok AFAIK, no ?

    yes – make a copy of header.php in the child theme, and remove that call, or add a new function call.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘when child theme overwrites function from parent theme’ is closed to new replies.