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:
- How do i best handle custom plugin page actions?
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Replacing Scripts in Admin Load_Scripts
- Password field is empty when using wp_signon();
- How to load library scripts in admin from plugins in noConflict wrapper?
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- How to import the css in the plugin admin area?
- Objective Best Practices for Plugin Development? [closed]
- How can I add an image upload field directly to a custom write panel?
- ajaxurl not defined on front end
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to add a javascript snippet to the footer that requires jQuery
- How to create an API for my plugin?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- How to enqueue JavaScripts in a plugin
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- Plugin Form Submission Best Practice
- How to include jQuery and JavaScript files correctly?
- Best way to abort plugin in case of insufficient PHP version?
- How can I configure Docker for developing and deploying a custom theme?
- What do you think about custom designed plugin/theme options UIs?
- No Error Log File, no debug info
- How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
- Plugin API for easy admin list table generation, handling & exporting of MySQL tables?
- Where to put third party PHP library?
- Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
- Export data as CSV in back end with proper HTTP headers
- How to use PanelColorSettings in custom Gutenberg block?
- Getting a peer review for my new plugin?
- Optimize shortcode callbacks
- Completely remove WP_Admin_Bar for specific user roles
- Can someone explain what wp_session_tokens are, and what are they used for?
- Load js/css files only on specific admin UI pages
- Get list of scripts / styles and show file which enqueued them
- API to trigger prompt on leaving page
- How to integrate a PHP webmail script into the backend of WordPress?
- Using filters and actions for plugin API?
- Is There A Hook To Process The Content Of The Text Widget?
- How to Change the Entire WordPress Admin panel Look and Feel?
- Show message on wordpress admin dashboard
- Init action hook running late after PayPal’s return url?
- Custom ReCaptcha Login
- How to log plugin errors to plugin error_log file
- jQuery in header or footer
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- Hook the Keydown Event in the TinyMCE Post Editor
- How to check WordPress website username and password is correct
- Which to use to execute code during the saving of a plugin settings page?
- Is it possible to add an admin page using add_submenu_page() and pass a var in the query string?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- how to use thickbox in admin?
- Log in from one wordpress website to another wordpress website
- How do I conditionally enqueue script for CPT single post type with plugin?
- How do you create a custom edit.php / edit pages page
- Cancel post save
- Using Primary Color in Plugin Block
- Add a jQuery function to admin pages
- Where to enqueue stylesheets for plugin?
- Problems after wp_set_password() containing an apostrophe
- Is it save to require plugin.php early to be able to use get_plugin_data() earlier?
- When is it appropriate to put functions on page template vs. functions.php?
- WP Cron doesn’t save or in post body
- Create a clickable name in WP_List_Table for Plugin Admin
- Custom theme sufficient or custom plugin neccessary for this feature set?
- When to check if a function exists
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- How to create custom home page via plugin?
- URLs of plugin resources?
- Two-step login process – Is it possible?
- Adding callback function for wp_ajax_ has no effect
- Sessions not creating correctly in custom function
- When is it too late to call the action wp_enqueue_scripts?
- Use js script from one plugin in another plugin
- Featured Image not showing in admin
- Problems with removing admin bar
- How to use wp_set_password in a plugin?
- Script won’t load via plugin class
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- Check if I am in the Admin Panel (wp-admin)?
- How do I approach removing menu items on the fly based on settings in my plugin?
- How to add custom content under plugin row in WordPress admin plugin list?
- How Can I setup WP CLI on Windows development machine running AMPPS?
- WP_LOCALIZE_SCRIPT doesn’t work
- How to put placeholder text in the main post input area?
- How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
- Nuance in adding CPT and TAX to a submenu
- Inserting JS snippet in the footer if there is no wp_footer?
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Can’t get JS code to work with shortcode
- Delete a specific item menu when I deactivate my plugin
- How to load the plugin only when logged in?
- How do you output enqueued scripts to an admin page?
- How do I add a javascript file to all admin pages via a plugin?
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- Multisite plugin development and wp_enqueue_script
- How to redirect to action on custom page within admin section
- is_page() function doesnt working
- Get the password key when using the wp_new_user_notification_email filter
- WP AJAX is not working, always returns 0