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?
- ajaxurl not defined on front end
- How can I configure Docker for developing and deploying a custom theme?
- Plugin API for easy admin list table generation, handling & exporting of MySQL tables?
- Completely remove WP_Admin_Bar for specific user roles
- API to trigger prompt on leaving page
- Show message on wordpress admin dashboard
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Log in from one wordpress website to another wordpress website
- How do I conditionally enqueue script for CPT single post type with plugin?
- Using Primary Color in Plugin Block
- Where to enqueue stylesheets for plugin?
- 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?
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- URLs of plugin resources?
- When is it too late to call the action wp_enqueue_scripts?
- Use js script from one plugin in another plugin
- Problems with removing admin bar
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- How do you output enqueued scripts to an admin page?
- Multisite plugin development and wp_enqueue_script
- is_page() function doesnt working
- Get the password key when using the wp_new_user_notification_email filter
- Order properties should not be accessed directly
- How to avoid loading same script twice?
- Is there any way to check for user login and send him to login?
- Can I individually style items in the backend widget list?
- How to deal with equal & similar arguments for a function?
- Executing a function upon webhook calling wordpress
- Customizer: widget-synced triggers twice
- Loading scripts with wp_register_script and wp_enqueue_script
- how to use hook deleted_user into custom function to delete user from custom table
- Adding Dropbox dropin js using wp_enqueue_script
- Proper way to pass credentials in a custom login form to avoid “headers already sent”
- Where to store the name of a custom table?
- maintaing consistent layout wordpress dashboard
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- Clearing caches on plugin uninstall
- Does wp_login only trigger before an user signs in into the admin panel?
- How to enqueue or include json file to a plugin
- Using ReactJS in the WordPress admin for plugin development
- template_redirect or admin-ajax.php?
- Creating Admin Plugin – Content of a page is displayed at global scope as well
- Show error message after exception handled
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Issue with contextual help overwriting existing content
- How to modify files inside wp-includes directory in wordpress
- How do I link to a php file in my plugin directory?
- How to set a cookie for logged in users to md5($user->ID . “my_secret”)?
- should i be checking for jquery before enqueing it in a plugin
- How to create custom settings page for custom plugin
- Plugin Development – Class Constructor Not Firing wp_enqueue_style action hook
- Wp-admin Custom User Management
- Create Widget or Enable Shortcodes in Sidebar
- Filter for admin (back end) ‘reply to’ comment
- How to make my shortcode load scripts and styles, from within the plugin?
- Redirect in WordPress plugin
- How do I get rid of my inclusion race-condition on wp_enqueue_script
- How to add custom view links to wp-admin/post.php?
- How do I validate extra pin field on my WordPress login form page?
- Enqueueing common php scripts in a plugin
- How to use a WP_Customize_Control outside of the Customizer?
- How do I duplicate a single post, with all its properties, and save it as a different post?
- check_admin_referer()
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Why won’t this submenu page show? – My First WordPress Plugin
- Allowing duplicating users with same user_login and user_email
- Hiding the WordPress login and password fields from login page
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Set widget icon in Customizer?
- redirect_to how to make it simply work with get parameter or similar?
- Default and warning messages & no login
- Determine if the current page, is being edited
- WordPress delete mysql rows with string
- How to enqueue an external Javascript file to Frontpage footer
- Associating special meaning with user id 0
- Theming Custom Plugin Page
- Issue with iframe in TinyMCE
- Script work on non logged in user but not work for logged in user?
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- Dynamic banner for use on external sites
- How do I store a custom dataset in WordPress to best take advantage of API?
- admin page passing $_POST variables to itself
- Get user logged in status from within a plugin. $current_user not defined
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- modify buddpress adminbar only in admin pages
- Need edit profile link in the menu for logged in users
- Create a Custom Login System in WordPress [closed]
- user can login from single account detail from multiple locations(computer) at the same time [closed]
- Custom plugin not appearing
- How to change the headline title for an admin page in a plugin?