If you run wp_enqueue_script()
inside a shortcode, which is essentially what you’re doing by calling enqueueAllMyStuff()
, the script is going to be queued up to be loaded in the footer. So if your shortcode runs a script as soon as it’s printed, the JavaScript file that it depends on won’t be available yet, and will cause this error.
The simplest solution is to update your script to wait for the document to have loaded. With jQuery you’d use jQuery( document ).ready()
, but in vanilla JS you can use:
<script>
window.addEventListener( 'DOMContentLoaded', function() {
do_cool_stuff();
} );
</script>
Related Posts:
- ajaxurl not defined on front end
- wp_localize_script is not adding a global variable for javascript
- AJAX call of function containing javascript which is not loaded (Plugin development)
- Ajax Response Error | just getting error as the response
- How to add a javascript snippet to the footer that requires jQuery
- How-to implement admin Ajax inside an admin WP_List_Table?
- What is nonce and how to use it with Ajax in WordPress? [duplicate]
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- Build path for a custom portfolio plugin
- Using AJAX in a plugin to submit form – REALLY confused
- Adding callback function for wp_ajax_ has no effect
- get all products of one category
- Get returned variable from a function to add_shortcode function
- WP_LOCALIZE_SCRIPT doesn’t work
- Admin-ajax.php appending a status code to ajax response
- Inserting JS snippet in the footer if there is no wp_footer?
- Can’t get JS code to work with shortcode
- How do I add a javascript file to all admin pages via a plugin?
- Cannot search post by taxonomy
- WordPress Ajax callback function from plugin – OOP
- WP AJAX is not working, always returns 0
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Frontend Ajax call not working using wp_ajax, wp_enqueue_script and wp_localize_script
- Fetching the value of forms in WordPress AJAX
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Replacing Scripts in Admin Load_Scripts
- Is there a way to ensure plugin script loads before another script?
- conditionally load javascript & CSS for do_action() calls from plugin
- What stylesheets are available in core?
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- How to localize admin.php only once
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Create custom HTML/JS app inside page
- Use just a shortcode from another page
- How to load library scripts in admin from plugins in noConflict wrapper?
- Enqueue script globally
- Update Data parameter of a wp_localize_script() call
- jquery & ajax sending data to php
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- Can’t get AJAX call working in custom plugin
- Bad Request in AJAX
- 400 Bad Request, in wordpress theme development, wp_ajax
- How to import the css in the plugin admin area?
- ajax recursive calls on wordpress returning answers outsite the function scope
- Are there any security risks when submitting data-attribute data through AJAX?
- My stylesheets are not enqueuing
- Enqueuing scripts and styles in custom plugins
- How to get error object returned by wp_create_user
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Data not insert and update through ajax and jQuery in admin page?
- WP ajax requests not stacking?
- AJAX button with success callback. (Titan Framework)
- Using function from enqueued .js file in theme in plugin?
- Enqueue a file that’s not js or css
- AJAX call returns ‘testtest0’ instead of ‘test’ – why?
- Best practice for plugin: always detect admin-ajax call?
- add_action wp_ajax_ not loading in plugin file WP Network
- Why is the form not updating when I select a new sector from the list?
- Plugin Form Submitting to admin-ajax.php instead of admin-post.php
- Ajax +wordpress onClick link redirect to new page and create html content
- wp_enqueue_scripts in a plugin’s class
- Loading Images from Javascript on the Front End
- Get cat parameter from admin-ajax
- WordPress (pagenow link) in ajaxurl change after i change plugin language
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Jquery php request is returning a weird result
- Posts form with AJAX request – Plugin development
- How to control ajax calls without effecting memory of server?
- Is “document loaded” different on admin side than public side?
- “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
- ajax call return 406 not acceptable for non logged users only
- Does $this context change in an AJAX callback?
- plugin css is not being applied to the page
- Adding External Gmap JS to WordPress
- WordPress Ajax not returning Response
- How do I ensure I can loop through every enqueued script and CSS?
- How to avoid conflict if a plugin already have included open library?
- Performing ajax request in wordpress
- Inserted data from database does not showing on front-page without referesh page?
- wp_ajax function return the html page
- ajax multiple Values
- Using JavaScript in WordPress page to call for server data using AJAX
- Javascript not being loaded only in custom taxonomy template
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Enqueue scripts based on site.
- How To do Ajax In WordPress Custom Plugin?
- admin-ajax.php returns “No Script Kiddies!” sometimes
- Ajax functionality not being called under wordpress plugin
- Array/List Edit in Backend
- Ajax not working to insert, query and result data
- WP Cron as Fast as WordPress AJAX?
- WordPress plugin: admin-ajax.php not passing data to custom function
- Ajax url value to pass ‘variable’ to use in query
- Ajax functions – no access to wp-admin.php only online
- Enqueue Script in custom plugin before other
- How to only Load scripts on variable products page
- PHPUnit Ajax Serialization of ‘Closure’ is not allowed
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Why my admin-ajax url returns 0 even after adding echo and die() at the end of function?
- WordPress plugin boilerplate AJAX functionality