Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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();
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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