For that I would suggest to use
'init'
hook.
According to codex
This runs after WordPress has finished loading but before any headers are sent
For more details visit codex explantion and examples for this hook;
You can find answer to similar question over here;
Related Posts:
- Hook into wp_head(); in a plugin
- Setcookie works on admin but not front end
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- Setting Cookie with init hook causes ‘header already sent’
- How to get session token of current user in wp_login hook?
- How To Make Sure That My Action Hook Executes Last
- How to replace a function using a child theme?
- Would there be anything stopping me from removing both wp_head and wp_footer?
- Add PHP code to header section from plugin
- How to remove a meta description or other contents
- Cookie cant be read even cookie is present
- Removing action from template class
- Why callback function is not working in wp_head hook?
- Where can I find a list of WordPress hooks?
- Is there a save_post hook for custom post types?
- Trigger custom action when setting button pressed
- Whats worth using add_action when we can simply use add_filter?
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Hook on trash post
- Which hook if user profile information is updated?
- Adding onload to body
- What is the earliest possible hook for safely using `is_front_page`?
- Are hooks called synchronously?
- Send data to 3rd party api with wp_remote_post on wp_login
- How to customize the WP admin default help contents
- Hide gutenberg option blocks
- admin_post hook not called
- deactivated_plugin hook: get the name of the plugin
- Is there a hook for user activation (after they click the email confirm)?
- function ‘wp_enable_block_templates’ not found
- How can I add a default description to uploaded files?
- Hook Widget to Woo Theme in functions.php
- Security around save_post hook
- How to pass arguments to add_action() [duplicate]
- How to use the post_updated hook before and after arguments
- Redirect users on specific post category or category page
- Returning ACF custom field from publish_post
- Stuck in redirect loop after using wp_login action
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- I don’t understand why I shoud use lostpassword_url hook?
- Hook after wp_enqueue_scripts
- action hook wp_head higher priority as all other plugins/hooks
- Hook any php file into the wordpress api
- WP CLI Get all Enqueued Scripts and Styles
- Delay an action until current action is completed
- How to properly setup an activation hook
- How to remove scripts/style added to customize_controls_enqueue_scripts hook by current active theme
- Help to change the text for new website notification (wpmu_welcome_notification)
- How to remove query string from current page URL?
- Event-Driven Pattern vs MVC?
- Using hooks with extra parameters
- Plugins rewrite rules the right way
- new_to_publish fires multiple times
- Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
- `rest_user_query` can’t access post author in post edit screen
- Add nofollow to custom widget posts
- Change Password Confirmed Email Text
- How do I trigger a post update within a get_posts() foreach loop?
- Register form: add custom field BEFORE default fields
- Custom Front End Registration – How Does the Key work in the Password Set Request?
- Lock user information once fields have been filled in
- How to distinguish on hook profile_update user registering, user resetting password or user updating profile?
- save_post hook to add terms getting deleted when using bulk edit
- Embeding style into the header via the function.php
- Add Different Actions To Different Page’s wp_footer
- Can I “protect” a page with a form asking for an email address?
- How to execute a hook asynchronously?
- Getting the post ID in parse_query
- Remove genesis_404 hook from genesis_loop [closed]
- What hooks do I need to hook into to capture ever wp_user creation/change?
- Neccessary to call add_submenu_page and add_menu_page from admin_menu hook?
- “Seen by” Feature in posts [closed]
- Adding custom Bulk Actions
- hook for loading page
- What hook to use to redirect based on $post
- How to call do_action() to pass arguments to hooked functions that take different number of args?
- Is it likely that do_action will have unexpected results?
- How to export category name and category link in wordpress json
- Error later wordpress 5.3.2 update. Please help
- How to abort a save operation with a WordPress hook?
- is_page not triggering
- admin_post_(action) hook create console log error
- Check if front page within function passed to action
- Hook after creating a post and retrieve infos from this post immediatly
- $new_pass always returns null – password_reset hook
- How to resolve 500 error in post listing page?
- Object oriented programming, add_action in constructor not firing
- Get new (not old) post inside transition_post_status hook
- How to Show Different Information to your authors/contributers
- Cannot override hooks.php
- Remove “enqueued” script from array
- Function is Missing an Action Hook
- How to access variables in the function where apply_filters() is called?
- PHP Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered
- change position of element using hook [closed]
- wp_footer content appearing in admin area
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- Callback API for getting response from fygaro payment gateway
- wp_trash_post not firing as expected (also applies to trashed_post)
- Changing login url