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?
- How to intercept a 404 error
- Whats worth using add_action when we can simply use add_filter?
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Hook on trash post
- Adding onload to body
- What is the earliest possible hook for safely using `is_front_page`?
- 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
- How get list all users who edited post?
- 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?
- 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?
- Plugins rewrite rules the right way
- Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
- Add nofollow to custom widget posts
- Change Password Confirmed Email Text
- 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
- What is the difference between add_action and add_filter [duplicate]
- load-* hook for dashboard
- What conditions must be met in order to upload .zip file to a multisite WordPress installation?
- How to hook code in ?
- wp_enqueue_script before wp_head
- Is it possible to add the_content filter upon login?
- Use an array of page template slugs and $hook
- wp_logout hook never triggered
- add short description under price
- How do I use pre_option_{option_name} correctly?
- post.php AJAX request not being called when publishing post
- WordPress media library allow uploading fake file
- What hook do I use if I want to update a user profile field when a new user is created?
- How to add custom tab page in backend?
- Add html code in admin page
- Hooking dynamic/variable named hook in all cases
- What hook to add at start of WordPress load
- Knowing if a post is sticky in the ‘save_post’ action. Where do I have to hook?
- How to read and write session data?
- Count when a post of a custom post type is deleted and store it in a theme option
- Can we change the hook firing sequence?
- Intercept loading of a certain page
- Add content in cpt archive page
- Creating custom post on registration in wordpress?
- Display custom user profile fields in wordpress
- profile_update not supplying old data
- Output Redirect Headers on Admin Dashboard Page
- add_image_size not working with after_switch_theme
- wordpress hooks
- Check when a setting has been changed
- Hook after creating a post and retrieve infos from this post immediatly
- add extra parameter in default hook in wordpress
- Exclude WooCommerce terminations from YOAST
- Hook triggered twice in a Woocommerce single product page
- set_post_format called after wp_update_post when using bulk edit?
- add hook restricted only to either plugins or themes?
- How to hook watchdog script for existence of a WP page?
- addaction hook cause redirection problem
- Cannot override hooks.php
- Getting all post/page IDs related to a soon-to-be-deleted tag/cat
- Hooking get_pages()
- Fire a hook programmatically
- Transform .wp-video to the native video player of the browser
- How do I override the user’s input when updating a custom post type’s permalink?
- How to add a new link to the default register form’s footer links?
- How to use the password_reset hook to validate new password and display error
- Use wordpress search hooks to search a second database
- woocommerce_add_to_cart_validation max quantity depending on user geoip [closed]
- theme.json is altering Group block HTML
- Not able to set userId and email at wp_set_current_user in Worpdress