0

I'm trying to override a parent theme filter in a child theme; I must have the syntax wrong as the override is being completely ignored. Here's what's in my child theme's functions.php:

//* remove and replace parent filter
function child_remove_parent_function() {
    remove_filter('filter_name','parent_function');
}
add_filter('filter_name','child_function');

//* my custom function
function child_function($link){
    //* function code here
    return $link;
}

The child theme is definitely in use - I initially tried copying & customizing the function and got the 'cannot redeclare function' error. Just not sure why I can't replace the filter.

I even tried leaving just

function child_remove_parent_function() {
    remove_filter('filter_name','parent_function');
}

to see if the outputted link would break but that didn't do anything either. What am I missing?

1

I do not see you actually calling child_remove_parent_function() in your code.

Another issue to be aware of is timing. It is counter–intuitive, but functions.php files are loaded in order of child first, parent second.

Overall you need to ensure two things:

  1. code works at all
  2. it is called at the appropriate moment, after parent theme is done with its set up
  • OK - would I just need to add add_action( 'after_setup_theme', ' child_remove_parent_function' );? – Arp Laszlo Oct 5 '15 at 13:23
  • I'm totally confused now. I know I can do this by editing the parent theme but that would be overridden by an update. Calling child_remove_parent_function() in my child theme's functions breaks the site. – Arp Laszlo Oct 5 '15 at 13:37
  • Tried function child_remove_parent_function() { remove_filter('filter_name','parent_function'); } add_action( 'after_setup_theme', 'child_remove_parent_function' ); but still no dice. Can I get some help from someone? – Arp Laszlo Oct 12 '15 at 11:39

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.