When using add_action, is it better to write:
add_action('blah', 'my_function');
function my_function() { return $something; }
or
function my_function() { return $something; }
add_action('blah', 'my_function');
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s purely a stylistic choice, both behave in exactly the same way.
Personally I prefer
as I feel it’s easier to identify the hooks when reading through code. If the function is particularly long then it may not be immediately apparent that it’s being hooked in.
For reference, the same question has been asked on quora – http://www.quora.com/WordPress/In-WordPress-is-it-best-practice-to-add_action-before-or-after-your-custom-function