Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Enqueue script globally

I’m not aware of any other way but to use both add_action lines, for a single function.

Example:

function my_enqueue_sripts_function_name(){
    
    // your enqueue logic here
    
}
add_action('wp_enqueue_scripts',    'my_enqueue_sripts_function_name' );
add_action('admin_enqueue_scripts', 'my_enqueue_sripts_function_name' );

There’s no rule that forbids you from adding the same function on multiple hooks.

Furthermore, if you need to know which action called the function, from within the function, you can use current_action() or current_filter()

Related Posts:

  1. How do i best handle custom plugin page actions?
  2. How to run a external JavaScript file on wp-admin if admin, and other if normal user?
  3. Replacing Scripts in Admin Load_Scripts
  4. Password field is empty when using wp_signon();
  5. How to load library scripts in admin from plugins in noConflict wrapper?
  6. Loading Modernizr (or other JavaScript libraries) for use in a plugin
  7. How to import the css in the plugin admin area?
  8. Objective Best Practices for Plugin Development? [closed]
  9. How can I add an image upload field directly to a custom write panel?
  10. ajaxurl not defined on front end
  11. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  12. How to add a javascript snippet to the footer that requires jQuery
  13. How to create an API for my plugin?
  14. Is it ever okay to include inline CSS in plugins?
  15. Plugins in symlinked directories?
  16. How to enqueue JavaScripts in a plugin
  17. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  18. Plugin Form Submission Best Practice
  19. How to include jQuery and JavaScript files correctly?
  20. Best way to abort plugin in case of insufficient PHP version?
  21. How can I configure Docker for developing and deploying a custom theme?
  22. What do you think about custom designed plugin/theme options UIs?
  23. No Error Log File, no debug info
  24. How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
  25. Plugin API for easy admin list table generation, handling & exporting of MySQL tables?
  26. Where to put third party PHP library?
  27. Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
  28. Export data as CSV in back end with proper HTTP headers
  29. How to use PanelColorSettings in custom Gutenberg block?
  30. Getting a peer review for my new plugin?
  31. Optimize shortcode callbacks
  32. Completely remove WP_Admin_Bar for specific user roles
  33. Can someone explain what wp_session_tokens are, and what are they used for?
  34. Load js/css files only on specific admin UI pages
  35. Get list of scripts / styles and show file which enqueued them
  36. API to trigger prompt on leaving page
  37. How to integrate a PHP webmail script into the backend of WordPress?
  38. Using filters and actions for plugin API?
  39. Is There A Hook To Process The Content Of The Text Widget?
  40. How to Change the Entire WordPress Admin panel Look and Feel?
  41. Show message on wordpress admin dashboard
  42. Init action hook running late after PayPal’s return url?
  43. Custom ReCaptcha Login
  44. How to log plugin errors to plugin error_log file
  45. jQuery in header or footer
  46. Enqueue script only when shortcode is used, with WP Plugin Boilerplate
  47. Hook the Keydown Event in the TinyMCE Post Editor
  48. How to check WordPress website username and password is correct
  49. Which to use to execute code during the saving of a plugin settings page?
  50. Is it possible to add an admin page using add_submenu_page() and pass a var in the query string?
  51. Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
  52. how to use thickbox in admin?
  53. Log in from one wordpress website to another wordpress website
  54. How do I conditionally enqueue script for CPT single post type with plugin?
  55. How do you create a custom edit.php / edit pages page
  56. Cancel post save
  57. Using Primary Color in Plugin Block
  58. Add a jQuery function to admin pages
  59. Where to enqueue stylesheets for plugin?
  60. Problems after wp_set_password() containing an apostrophe
  61. Is it save to require plugin.php early to be able to use get_plugin_data() earlier?
  62. When is it appropriate to put functions on page template vs. functions.php?
  63. WP Cron doesn’t save or in post body
  64. Create a clickable name in WP_List_Table for Plugin Admin
  65. Custom theme sufficient or custom plugin neccessary for this feature set?
  66. When to check if a function exists
  67. Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
  68. How to create custom home page via plugin?
  69. URLs of plugin resources?
  70. Two-step login process – Is it possible?
  71. Adding callback function for wp_ajax_ has no effect
  72. Sessions not creating correctly in custom function
  73. When is it too late to call the action wp_enqueue_scripts?
  74. Use js script from one plugin in another plugin
  75. Featured Image not showing in admin
  76. Problems with removing admin bar
  77. How to use wp_set_password in a plugin?
  78. Script won’t load via plugin class
  79. Plugin Loading Scripts and Styles on Every Page – Even when not being used
  80. Check if I am in the Admin Panel (wp-admin)?
  81. How do I approach removing menu items on the fly based on settings in my plugin?
  82. How to add custom content under plugin row in WordPress admin plugin list?
  83. How Can I setup WP CLI on Windows development machine running AMPPS?
  84. WP_LOCALIZE_SCRIPT doesn’t work
  85. How to put placeholder text in the main post input area?
  86. How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
  87. Nuance in adding CPT and TAX to a submenu
  88. Inserting JS snippet in the footer if there is no wp_footer?
  89. Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
  90. Can’t get JS code to work with shortcode
  91. Delete a specific item menu when I deactivate my plugin
  92. How to load the plugin only when logged in?
  93. How do you output enqueued scripts to an admin page?
  94. How do I add a javascript file to all admin pages via a plugin?
  95. Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
  96. Multisite plugin development and wp_enqueue_script
  97. How to redirect to action on custom page within admin section
  98. is_page() function doesnt working
  99. Get the password key when using the wp_new_user_notification_email filter
  100. WP AJAX is not working, always returns 0
Categories plugin-development Tags customization, login, plugin-development, wp-admin, wp-enqueue-script
Password protected page with a form submits for me fine but for others redirects them back to the password prompt
Bad request 400 from custom ajax call

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress