The Plugin Developer Handbook recommends using plugins_url()
to create the URL to the JS file. Try using that function inside your script loader, and using a different handle for the script depending on the context (like prefixing the admin script name with “admin-“) to avoid conflicting script registration.
Alternatively, you can register the script just once, and enqueue it when needed on the enqueue hooks.
Related Posts:
- How to include jQuery and JavaScript files correctly?
- jQuery in header or footer
- Use js script from one plugin in another plugin
- Can’t get JS code to work with shortcode
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Where to call wp_enqueue_script in a plugin with custom template?
- should i be checking for jquery before enqueing it in a plugin
- Custom Plugin – CSS works, JS doesn’t
- Is “document loaded” different on admin side than public side?
- Append php file to footer
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- 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 enqueue JavaScripts in a plugin
- How to implement color picker from wordpress in my plugin?
- How can I run AJAX on a button click event?
- Add async script
- Load js/css files only on specific admin UI pages
- How to provide translations for a WordPress TinyMCE plugin?
- Can I use the wp media uploader for my own plugin?
- Get list of scripts / styles and show file which enqueued them
- How-to implement admin Ajax inside an admin WP_List_Table?
- API to trigger prompt on leaving page
- Customizing the 3.5 “Add Media” popup (Backbone.js)
- Test to see if jQuery or Prototype is queued by another plugin?
- Include third party Javascript library which is not included in WordPress
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- Hook the Keydown Event in the TinyMCE Post Editor
- How do I conditionally enqueue script for CPT single post type with plugin?
- Where to enqueue stylesheets for plugin?
- How to Add a .js file Only in one specific Page Dynamically to Head
- lodash dependency in a Gutenberg plugin
- wp_localize_script $handle
- How to prevent loading of all plugin’s resources?
- How to trap “Publish” button to check for meta box validation?
- Pass javascript result to shortcode executer function
- The changes I make to an external JS file of my WP plugin are only applied after I clear my browser’s cache
- `wp_set_script_translations` with `wp.i18n` does not return translated strings in simple plugin
- When is it too late to call the action wp_enqueue_scripts?
- How do I only load js on the post-new.php and post.php pages in admin?
- Script won’t load via plugin class
- creating elements/innerblocks via rangecontrol
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- Dequeue / Deregister script and replace it with a new plugin
- Making a custom widget that includes a tinymce and works in Site Origin Page Builder
- Looking for callback function after Gutenberg is rendered?
- What’s the better way to add an inline script?
- Inserting JS snippet in the footer if there is no wp_footer?
- How do you output enqueued scripts to an admin page?
- Multisite plugin development and wp_enqueue_script
- Gutenberg: useDispatch is not a function – @wordpress/data included
- Make a list with header and subtext in Gutenberg blocks
- Gutenberg – What is the best way to save/update post meta?
- Prevent Javascript Facebook SDK Conflicts in plugin
- is_page() function doesnt working
- How to Load Plugin JS in theme’s footer section
- how to include javascript file and css file in wordpress
- Print WordPress username id inside JavaScript
- Mixing Regular Javascript With jQuery in a Plugin
- How to avoid loading same script twice?
- Why is my javascript not invoked in my hooks except wp_head?
- Enqueue scripts in footer
- Loading scripts with wp_register_script and wp_enqueue_script
- Adding Dropbox dropin js using wp_enqueue_script
- Replacing Scripts in Admin Load_Scripts
- Is there a way to ensure plugin script loads before another script?
- React JSX in WordPress Plugin Development
- Is there an event or an other method that tells me the preview is loaded?
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- conditionally load javascript & CSS for do_action() calls from plugin
- What stylesheets are available in core?
- Enqueue WordPress plugin scripts below all other JS
- How to prevent UNDO on guternberg block editor
- Do I have to worry about useState causing a re-render?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- wp.template() returns tags in Ajax response
- Gutenberg: import dependency or assign from global variable?
- How to enqueue or include json file to a plugin
- My WordPress plugin cannot load my JavaScript file
- javascript datatables in a plugin
- How to load library scripts in admin from plugins in noConflict wrapper?
- add javascript files only when plugin is called?
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Inserting code to HTML view from a pop up initiated from visual view
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- How can I avoid conflicts between plugin and theme?
- Enqueue script globally
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- WP Plugin Running before jQuery
- wp_localize_script is not adding a global variable for javascript
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- How to import the css in the plugin admin area?
- Loading custom js file on the admin page through plugin
- My stylesheets are not enqueuing