3

I have a theme and I need to override some specific parts|behavior of it specifically on the functions.php file. I know the best practice here is doing this at child theme by placing a custom functions.php. Now this is part of the original file:

function mytheme_setup() {
    ...
    add_image_size( 'mytheme-l-thumbs' , 750 , 423 , true);
    add_image_size( 'mytheme-m-thumbs' , 555 , 313 , true);
    add_image_size( 'mytheme-s-thumbs' , 450 , 254 , true);
    add_image_size( 'mytheme-square-thumbs' , 750 , 750 , true);
    add_image_size( 'mytheme-nocrop-thumbs' , 750 , 1500 , false);

}

add_action( 'after_setup_theme', 'mytheme_setup' );

And I want to override each add_image_size by set crop to false on my child theme. I have tried by copying & pasting the function on child theme but I ended up with this error:

Cannot redeclare mytheme_setup() (previously declared in /themes/mytheme-child/functions.php:11) in /themes/mytheme/functions.php on line 88

How I can do that?

  • @jgraup that was my first though but I am not sure at all, will try now, thanks – ReynierPM Jan 9 '16 at 4:52
  • @jgraup nope, didn't work, see my edit at OP – ReynierPM Jan 9 '16 at 4:57
3

When a function is hooked, it is easy to change that in a child theme. What you need to do is

  • Remove the original call back function

  • Copy the function to your child theme and rename it.

  • Do your customizations as needed

  • Rehook your call back function

You can try the following:

// Remove the callback function from the hook
remove_action( 'after_setup_theme', 'mytheme_setup' );

// Copy the function, rename and do what you need
function my_new_callback()
{
    // Modify what you need
}

// Rehook your custom callback
add_action( 'after_setup_theme', 'my_new_callback' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.