0

In a parent theme I have a function like this, that removes hyperlinks from comments:

function preprocess_comment_remove_url( $commentdata ) {

  //some code...

    return $commentdata;

}
add_filter( 'preprocess_comment' , 'preprocess_comment_remove_url' );

I want to unhook this function, as I want to use links in my comments. I can't seem to unhook it. I tried different things. This is my most recent approach:

function child_remove_parent_functions() {
    remove_filter( 'preprocess_comment', 'preprocess_comment_remove_url');
}
add_action( 'wp_loaded', 'child_remove_parent_functions' );

But that also doesn't work. How do I unhook the parent function?

0

wp_loaded would fire too early - you can't remove a hook before it's been added.

I'd try adding your own hook with a higher priority, at the same level as the parent's hook. That is, not inside an action.

add_filter( 'preprocess_comment' , 'my_preprocess_comment_function', 5 );

Then within your function, remove the parent function:

function my_preprocess_comment_function( $commentdata ) {
    remove_filter( 'preprocess_comment', 'preprocess_comment_remove_url' );
// Do anything else you need to do
return $commentdata;
}

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.