Performance impact of hooked functionality is determined by how often hook fires and how intensive the operation is.
init only ever fires one per load, so multiple runs are not a factor for it.
Mostly the thing you need to pay attention to is context. If your logic fires on every load and result is conditional the first thing it should do is determine if the context is the one you want. In all other cases that it the only thing it should do.
As long as your context check is lightweight the performance impact should be perfectly insignificant.
If your context check is heavy for some reason you might want to find a more specific hook (such as those in template loader logic) that would fire less and in more narrow circumstances. But for something as simple as example you made that won’t be necessary.
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?
- Custom plugin init action causing general slowness
- 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)
- 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
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- Customizing subject in comment notification e-mails
- enqueue script only if it is not already enqueue
- Plugin child folder?
- merging an array to an existing array using add_filter
- Retrieving plugin options value saved through setting
- How to ‘clone’ a wp plugin to make small changes
- How to slice an array using posts_per_page? [closed]
- Enqueue WordPress plugin scripts below all other JS
- woocommerce payment gateway callback not firing [closed]
- White page by using filter template_include
- How to export post 2 posts WordPress plugin data [closed]
- Customization API for plugin development
- User switching only with specific role and return
- Fromcraft Plugin On click submit button [closed]
- Adding Font Awesome to WP Plugin
- How to test ‘upgrader_process_complete’ hook in plugin development?
- Plugin Not Working After Being Uploaded To WordPress Plugin Repository
- Difference and examples of esc_attr__() and esc_attr_e()
- Issue running db create table query from static method
- remove_action not removing add_action from constructor
- How to add a WordPress Nonce for this form to avoid CSRF
- Overriding current theme files via plugin
- How to create a plugin that includes all the other plugins?
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- How to call external functions from a PHP script in a WordPress plugin?
- How to get Recent Post From Each Category with Thumbnail?
- How use wp_insert_post and add og:custom tags?
- How to change “Read More” text?
- Using id to show item
- How to use wp_editor and save its data in wp_posts table
- My WordPress activation hook isn’t working
- Shortcode and WP query using category attributes
- Securing a plugin pop-up window
- Is admin section completely customizable in terms of styling?
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Better way to run heavy scripts using WordPress database
- how to check plugin name unique or not?
- Exclude specifed files from plugin editor
- WordPress ajax not working in registration
- Filter for modifying image on upload
- Jquery post responses 500 error after some time and lastly an 503 error
- How can I delete the options from DB when the plugin is deleted?
- Custom wordpress plugin does not save select element
- I’m getting the following error: Fatal error: Uncaught Error: Call to undefined function oil_paint_regeneration() [closed]
- how to code activate/deactive button of custom plugin within backend?
- move setting data from wordpress api to codestar freamwork
- How to access the page without registering in wordpress
- WordPress Plugin translation not working EN To FR
- Error 400 Invalid “products[1].productId” Kinguin [closed]
- How to create new title and its description inside a section in WP Customizer?
- Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1
- How to customize WP_Error (REST JWT authentication plugin) [closed]