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.

This is a function loaded by the parent theme. Through the child theme, I want to change this function to say is_single instead of is_singular. What would be the correct way to achieve this?

add_action('wp_head', 'dt_specific_enqueues');
function dt_specific_enqueues() {

    if (is_singular()) {
        wp_enqueue_script( 'comment-reply' );
    }

}
share|improve this question

2 Answers 2

up vote 1 down vote accepted

The parent theme's functions.php will load automatically. You don't need to "read" it, and you don't want to "hack" it either manually, which will be overwritten, or programatically, which is very resource intensive.

Your theme is enqueueing the script on the wp_head action. You just need to remove that callback and add a slightly modified one. The trick is that your child theme's functions.php loads after your parent functions.php so you need to get the timing right.

function dequeue_dt_specific_enqueues() {
  remove_action('wp_head', 'dt_specific_enqueues');
}
add_action('after_setup_theme', 'dequeue_dt_specific_enqueues');

Then add back your own version:

function altered_dt_specific_enqueues() {
  if (is_single()) {
    wp_enqueue_script( 'comment-reply' );
  }
}
add_action('wp_head', 'altered_dt_specific_enqueues');
share|improve this answer

You can use remove_action to remove a particular action done by your parent theme (within your child theme, before adding your own action to that hook [wp_head]) and then add your own action with add_action in your child theme.

References:

Remove Action

Add Action

share|improve this answer

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.