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
- 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 to provide translations for a WordPress TinyMCE plugin?
- How-to implement admin Ajax inside an admin WP_List_Table?
- 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 to Add a .js file Only in one specific Page Dynamically to Head
- 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
- creating elements/innerblocks via rangecontrol
- Looking for callback function after Gutenberg is rendered?
- Inserting JS snippet in the footer if there is no wp_footer?
- Multisite plugin development and wp_enqueue_script
- Gutenberg: useDispatch is not a function – @wordpress/data included
- 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 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?
- Loading scripts with wp_register_script and 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?
- 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
- My WordPress plugin cannot load my JavaScript file
- 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)
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- WP Plugin Running before jQuery
- How to import the css in the plugin admin area?
- My stylesheets are not enqueuing
- Enqueuing scripts and styles in custom plugins
- How to enqueue scripts in right way in a plugin?
- Translate javascript with WordPress built-in localization API for static strings
- Need help about understand api, wp, $ syntax in WordPress plugin script
- Insert Into Post Not Working For Audio File Using jQuery
- Developing the save function in Gutenberg blocks
- Using function from enqueued .js file in theme in plugin?
- Enqueue a file that’s not js or css
- How to insert HTML/CSS/JS into my iframe plugin?
- Is there a WordPress plugin to design WebGL? [closed]
- wp_enqueue_scripts in a plugin’s class
- Loading Images from Javascript on the Front End
- How to write a shopping queue line plugin with a queue button?
- wp.media libary pdf type
- wp.media gallery collection sometimes undefined
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- Rerender core Templates with with ToggleControl but it doesnt recognize block type
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- converting a node.js project into a wp plugin
- How to use setAttributes outside of the edit function return
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Reading plugin settings in esnext wordpress block
- plugin css is not being applied to the page
- Adding External Gmap JS to WordPress
- Load script on frontend from widget plugin
- How do I ensure I can loop through every enqueued script and CSS?
- WordPress with React: Saving and Using Data Collected with fetch
- How to avoid conflict if a plugin already have included open library?
- Using JavaScript in WordPress page to call for server data using AJAX
- Javascript not being loaded only in custom taxonomy template
- Ajax Response Error | just getting error as the response
- Enqueue scripts based on site.
- Uncaught ReferenceError: kpoejy is not defined
- Remove from a div by class name from post page if post author role is not administrator
- Enqueue script not working
- On one of my sites a file is shown as 404 but the file IS there
- Enqueue Script in custom plugin before other
- How to only Load scripts on variable products page
- How can i add insertion point between inner blocks in my custom block like core blocks
- How to get the value entered in the input field in wordpres
- Insert meta-description into Yoast-SEO input-field via JavaScript