最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - How Do I Unhook This Parent Theme Function?

programmeradmin3浏览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?

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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;
}
发布评论

评论列表(0)

  1. 暂无评论