Makes no difference. Despite the fact add_action
doesn’t actually check if the callback is indeed callable (i.e. is a valid function/class/method), PHP will first “load” function and class definitions before executing inline code, hence why you can do something like:
wpse_185390_function(); // Perfectly fine, even though the function is defined "afterwards"
function wpse_185390_function() {
echo 'I\'m down here!';
}
It’s entirely up to you if you “hook” before or after the definition – I personally prefer after for consistency (it’s how pretty much all WordPress core does it).
Related Posts:
- How do I enqueue a script to run inside the Gutenberg editor?
- enqueuing React script and hooking its target div fails to load script
- How to call a static function in add_action() inside another static function?
- Why is my css and js not enqueued until footer?
- How do I dequeue js/css at the last possible moment?
- remove_action or remove_filter with external classes?
- Why does save_post action fire when creating a new post?
- Difference between do_action_ref_array() and do_action()
- Why is there both a save_post and wp_insert_post action?
- When is admin_init Action ran?
- Can an action callback prevent the parent from continuing execution?
- How can I find out what functions are assigned to actions?
- Disable WooCommerce action
- When can you get current page ID and initialize hooks right after?
- How can I remove the WP menu from the admin bar?
- add_action customize_register not working
- Passing arguments into ‘init’ function
- How to use conditional add_action for WordPress
- WP Schedule Event – Every Day When First Visitor Comes
- How to remove an action that is added inside a class
- When is it too late to call the action wp_enqueue_scripts?
- add action which returns modified value
- WordPress admin WP_table_list show incorrectly
- How to add a checkbox inside the “Publish post” widget?
- Very stubborn wp_register_script / add_action vs remove
- What’s the usage of action do_meta_boxes?
- How can I invoke an action after a CiviCRM triggering event?
- Custom bulk actions in WP 3.7.1
- Remove action from a plugin class
- Modify query in pre_get_posts action is messing up my nav menu
- Exclude trash from save_post
- How to check if an action is already fired?
- add_action and wp_head not display content in head section
- use add_action(‘wp_head’) in a widget
- Preventing frontpage to be deleted/moved to trash
- Selectively applying action based on role
- How to remove a custom action on child theme?
- Action hook on only publishing post not on editing or updating
- Deregister scripts on unnecessary pages using remove_action
- Prioritizing wp enqueue scripts error
- how can I use add_action run another function when publishing new post?
- Performance : Duplicating `add_action`
- add_action in class and use it in theme
- Better action hook for creating table than after_switch_theme and switch_theme action hook
- Adding the hook ‘vc_before_init’ inside a object
- How to apply action the_post to the post that is only being mainly displayed
- admin_notices on runtime in function
- Using several add_action with parameters inside a class
- Action hook load_textdomain $domain variable
- Action hook for editing post
- add_action and do_action: multiple calls to same callback?
- remove_action returns false regardless of priority
- Set a custom display_name on user_register?
- How to make an action run in the background?
- WP cron doesn’t pass through my arguments
- how to add submenu item under parent menu item with code
- Why does my wp_safe_redirect output the ERR_TOO_MANY_REDIRECTS error?
- Re-order Woocommerce single product and echo div around moved & duplicated Woocommerce hooks
- jQuery code not working when included in functions.php
- Custom Post type forgetting data
- Insert custom postmeta when custom post type published
- Call do_action class’s function
- Create post revision on slug change
- Is dynamic action name building a bad practice?
- Is it good practice moving the main stylesheets after the plugin styles?
- Overide enqueue in non plugable function via child theme
- Can’t Get Metabox Data Saved Assistance Needed
- is there an update_post_meta action
- A unique wp_schedule_single_event() for each post?
- Add new users to “add new user” page on admin’s dashboard
- Is this the correct way to enqueue style sheets from parent theme and then from child theme in wordpress?
- Change Post Publish Date to Post Modified Date in All Places
- add_action to wp_head is added, but not called
- Custom CSS not being added by plugin
- Insert Google authorship into WordPress header
- add_action before theme setup
- How can I get the user that publishes a post?
- add_action which contains first argument admin_print_scripts-$page
- Dynamic wp_enqueue_scripts?
- update_user_meta not updating
- How do i know which action / filters are called when i call get_option()
- How can I get more out of `$post` in an `add_action` callback?
- Remove action not working in child theme
- Call to Action Button – Resize Help [closed]
- Translate are not working for standard admin
- add_action init breaks site on PHP 7.1
- I can’t enqueue Suggest.js in frontend – not added
- Why is this require statement not working?
- action future_post returns wrong date
- Hook into admin_notices after sending mail
- save_post action not firing when save
- WooCommerce wp_insert_post action firing on every save
- WordPress’ work or execution flow manipulating $wpdb
- Add-action in function
- Building WP Web App: Creating a Feed for post revisions
- Can admin_bar_menu or another action be used to modify the admin bar on the admin side?
- What is the first action or filter executed by wordpress?
- Using add action for class with construct
- Webhook: save_post action fires wp_remote_post twice
- A way to see real changes of posts inside an action?