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?
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?
Share Improve this question asked May 1, 2020 at 12:58 TheKidsWantDjentTheKidsWantDjent 3154 silver badges20 bronze badges1 Answer
Reset to default 0wp_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;
}