0

My parent theme has a file with a class that defines ads for that specific theme. It is required in functions.php. My child theme needs a duplicate file with different ad parameters so I would like to not include the parent theme's file.

Is there an easy way to ensure the parent theme file will not be required in the child theme?

1 Answer 1

0

You could use is_child_theme() in the parent theme's functions.php file:

if ( ! is_child_theme() ) {
    require( 'path/to/ads/file.php' );
}

Update

If you don't want to edit the parent theme -- for instance, so that any updates to the parent theme won't overwrite what you've done -- you could do something like this in the child theme's functions.php file:

global $ads_class; // whatever your ads class is named
if ( 
    is_child_theme() && 
    ( 
      class_exists( 'Ads_Class' ) && 
      'Ads_Class' == get_class( $ads_class) 
    )
   ) {
    $ads_class->__destruct();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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