Anonymous functions in WordPress hooks
问题 WordPress hooks can be used in two ways: using callback function name and appropriate function add_action( 'action_name', 'callback_function_name' ); function callback_function_name() { // do something } using anonymous function (closure) add_action( 'action_name', function() { // do something } ); Is there any difference for WordPress what way to use? What is prefered way and why? 回答1: The disadvantage of the anonymous function is that you're not able to remove the action with remove_action.