W
W
Way2018-05-02 17:03:06
WordPress
Way, 2018-05-02 17:03:06

How to do remove_action or remove_filter if add is done via anonymous function?

How to remove_action or remove_filter if add is done via an anonymous function?

add_filter( 'wp', function() { echo 'test'; }, 345 );

I try this option but it doesn't work
remove_filter( 'wp', function(){}, 345 );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ainur Valiev, 2018-05-02
@wayheming

assign an anonymous f-th to a variable. in the removal of the filter, hook specify it.

add_action( 'the_post', $my_the_post_action = function( $post_object ) {
  // modify post object here
  var_dump($post_object);
} );
remove_action('the_post' , $my_the_post_action);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question