If you want your function to fire only once, you can use other hooks.
wp_head might be useful in your situation since it is fired before the rest of the template is rendered.
template_redirect is also fired before rendering the template.
If the sequence doesn’t matter to you, you can fire it at last using wp_footer or get_footer hook.
Related Posts:
- Where is the best place to use add_filter
- When can you get current page ID and initialize hooks right after?
- Using the ‘draft_to_publish’ hook (post status transition)
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How can I limit functionality in one version of a plugin?
- Shortcode display outside the div
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Can a plugin add to header/footer/body content?
- Is it possible to add an action to the currently running action?
- Action on post publish
- How to add inline css/js inside a shortcode
- How to call bind function in wordpress actions or hooks
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- add action wp_head not working
- What are the benefit in adding hook in the init() hook?
- add_action in functions.php, do_action in plugin?
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- How to check current user before all actions and filters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Add action to fire when a published post is updated
- How to pass variables to a function argument using add_action [duplicate]
- Submit Form data to another page via Ajax (WordPress Way)
- Does using `add_action( ‘init’…` cause performance issues?
- Hook for page Request?
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- I cannot include a file in my plugin settings page
- Why do actions with class and public method don’t fire __construct()
- The function called on the wp head hook becomes null
- Nested Actions and Filters
- Passing function into add_action always returns the first argument
- Get post content inside plugin class method
- Remove action added in plugin class from theme
- echo plugin results on pages
- Plugin Hook: Get posts
- Is it possible to cancel a post status transition?
- How wordpress plugin hooks works? [duplicate]
- add_action() not working for admin
- Edit plugin without hooks in functions.php
- Making plugin unique to not conflict with plugins with the same name
- How to find out if option exists but is empty?
- Is dynamic forms/entries possible in Widget?
- How to get posts by content?
- Trigger a custom wordpress plugin with a linux cron
- Add_rewrite_rule doesn’t add custom url in plugin
- Is this plugin being loaded before file.php, subsequently not allowing me to use certain functions?
- How do I write into a file (css)
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Where should I save an API key of my user when installing my plugin?
- How to make a customize role and view a specific plugins base on that role?
- Allow users of my plugin to define their own shortcode rather than use mine?
- CRUD and Frontend show from a custom table without shortcode
- Map Custom Registration Fields to WordPress User Roles
- Issue Tracker from pre exsisting table [closed]
- Removing an action from wp_footer called in a class that’s inside a bigger class
- Can I load the textdomain before a plugin is activated?
- Create tabs in admin options page from custom post type loop
- Count posts by type including drafts and pending posts
- Problem with removing plugin action
- edit_user_profile and show_user_profile are not firing inside a class
- Separate database for a wordpress plugin
- WordPress Multisite: Programmatically Activate / Deactivate a Plugin of a Specific Blog
- composer not working on my plugin when i upload it to my website
- What is the WordPress approach to custom data?
- How to remove a class function from a plugin by using remove_action()?
- How to rewrite URL and get the values?
- Disable plugin visibility at the plugin directory
- How to deactivate my plugin upon deactivation of NextGen
- Widgets are not displaying in the admin panel
- How to overwrite the category template in a plugin
- Content-Security-Policy implementation with WordPress W3Total Cache plugin installed
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- How to write different events from different functions in my file to a log file in WordPress
- Create a form and have custom menu display based on user answers?
- How to make a plugin api route have permission?
- Modify Plugin PHP Class in Child Theme – Correct Method
- Problem with conditional woocommerce custom checkout field
- Change wp_mail SMTP settings for each E-Mail
- WordPress Thumbnail add action if no thumbnail
- How can I add the custom taxonomy categories to the posts and pages?
- Pass strings to plugin function [closed]
- How to create a page template using custom plugin
- WordPress 3,5 and Jquery version
- contact form 7 captcha support anyother captcha plugin? [closed]
- Function not being called on form submit, only blank admin-post.php page
- How to give specific class name to category in wordpress with code snippets
- WordPress.Security.NonceVerification.Recommended
- BBPress Customization with Custom Plugin
- How do I apply different block supports to different parts of my custom block?
- Remove 3rd party plugin notices from within own plugin
- Custom Gutenberg blocks not showing in WP editor