You can wp_enqueue_script in your shourtcode. Here are the code I fixed.
Register your JS file
function wh_enqueue() {
wp_register_script( 'wh-ajax-app', WH_PATH . '/js/write-here-ajax.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wh_enqueue' );
and enqueue in your shortcode function
function ajax_write_here(){
wp_enqueue_script( 'wh-ajax-app' ); // Enqueue your script here
$output="<div id="write_here_ajax_wrap"></div>";
return $output;
}
add_shortcode('write-here-ajax', 'ajax_write_here');
This will only load your JS file on the page has shortcode inserted.
Related Posts:
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Why is my ajax call refreshing the page?
- Admin-ajax.php is dying “0” without processing function
- How to create popup same as wordpress popup feature
- Check if email address exists front end with AJAX in a plugin
- How to put JQuery/Ajax inside shortcode?
- Ajax contact form widget plugin data not insert in database
- Create shortcode to echo javascript
- How to add a dvi tag to a shortcode then change a generated text using jQuery
- Ajax request sends url rather than data
- wc_get_template_part doesnt display the content [duplicate]
- JS working when used normally but not in wordpress
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Overwriting Plugin’s Ajax callback function from theme
- WordPress ajax not working in registration
- Ajax, jQuery and WordPress
- How to get site homepage from plugin?
- Load css classes after using ajax calls
- Jquery post responses 500 error after some time and lastly an 503 error
- Custom media upload content for inserting custom post shortcode
- Checking if an attribute exists in a shortcode
- enqueue script only if it is not already enqueue
- Loading shortcode with ajax
- How to fetch serialized data from wordpress options
- Execute a function using ajax
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- How do I use WordPress PHP functions in my Javascript code?
- What’s the point of using WordPress’s built in admin-ajax.php?
- How to remove an Ajax action
- jQuery function didn’t work in my plugin
- Ajax gives 400 error
- Demystifying and understanding shortcode nomenclature
- Confused about shortcode and settings values
- Running jquery script after shortcode [closed]
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- WooCommerce get_price returning wrong price when used via ajax
- Simple ajax call not working in wordpress plugin
- Form isn’t inserting data into database with ajax plugin
- AJAX search posts and pages
- __callStatic method handler passed to add_action causes bug in PHP
- Making a Template for a CPT created by a plugin
- Best place for if/else piece of code related to custom plugin?
- jQuery for custom plugin not working with Divi theme
- Creating shortcodes in plugin
- How can I inject options into an select tag inside the widget form?
- How to create a custom shortcode based on the layout?
- How to prevent plugins from loading jQuery
- Inject HTML meta tag inside wordpress tag using add_shortcode
- how to insert data in wordpress table usnig jquery ajax
- Redirect to another page using contact form 7? [closed]
- Namespaced shortcode?
- Admin AJAX doesn’t work in plugin admin page – Even though code is copied verbatim from WordPress Codex
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- Why am I unable to load scripts in head in plugin?
- WordPress front end AJAX. Return 0 :?
- Using WordPress to build membership Page
- How to use template inside plugin shortcode with variables for big HTML code
- Asynchronous request in wordpress
- strange shortcode error: does shortcodes requires any dependency?
- How do I make sure that my plugin only runs on article detail pages?
- How to rewrite URL and get the values?
- WordPress API functions not working at AJAX functions.php call
- How to prevent tabs from opening all at once
- Calling a class method instantiated by ajax call in wordpress [closed]
- grab or load text on demand
- How do I reinit WordPress plugins dynamically using jS?
- Error datatable whit ajax
- WP Ajax DB issues
- How to call function in WordPress on button click?
- Hide content for specific users with id
- jQuery Ajax not loading page with ACF fields
- Why is my shortcode not working?
- Overwrite js code using WP_Footer
- Get shortcode attribute for AJAX call
- WP Plugin CSS not being applied to page
- Modify Plugin PHP Class in Child Theme – Correct Method
- Storing Array of values into wordpress options
- My ajax request don´t work and return 0
- Can’t find variable is_single in my jQuery plugin
- How can I use wp_ajax_response for front-end error reporting?
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- Not getting result using ajax on wordpress
- How to Add Jquery FullCalendar in wp plugin in admin
- AJAX doesn’t pass variables to the php function in the plugin
- Why function hooked using object are executing at all time?
- Hyperlink to execute PHP
- How to load a plugin when doing an Ajax call? [duplicate]
- Trying to override/intercept a PhotoMosaic gallery link in WordPress using jQuery
- WordPress plugin ajax post parameter
- Capturing POST data
- Ajax in Plugins: returns the whole page
- Shortcode return is printing a 1 afterward
- Any way to hook into WP after a page displays?
- Integrating WordPress Content into a jQuery Slider
- wordpress Ajax success doesn’t return the value
- Ajax button “Load more” is not loading correct language version posts for logged out users
- Inline AJAX script passing variables to PHP
- wordpress admin-ajax bad request 400
- Display file contents within Plugin