How to check if which hook triggered the call to a function?

  • Unknown's avatar

    I have a situation where I have a function hooked to more than one custom hooks. How to check in the callback function which custom hook triggered the call?

    Or the question in code will be

    
    add_action('my_test_hook_1','my_test_callback_function');
    add_action('my_test_hook_2','my_test_callback_function');
    add_action('my_test_hook_3','my_test_callback_function');
    add_action('my_test_hook_4','my_test_callback_function');
    
    function my_test_callback_function(){
    
        $called_action_hook = ; //Some magic code that will return current called action the hook
    
        echo "This function is called by action: " . $called_action_hook ;
    
    }
    
  • Hi there,

    What is your site URL? Based on what you are describing, it sounds like your site is using the open-source WordPress.org software, and in that case, you would need to seek help at these forums:

    https://wordpress.org/support/forums/

    These forums are for WordPress.com-hosted sites only. If you want to know more about the differences between WordPress.com and WordPress.org you can read this document:

    WordPress.com vs. WordPress.org

    Thanks!

  • The topic ‘How to check if which hook triggered the call to a function?’ is closed to new replies.