Script to run at completion of Page Loading
yes, WordPress has a function for loading javascript files: http://codex.wordpress.org/Function_Reference/wp_enqueue_script the last argument takes either true or false to load in the footer
yes, WordPress has a function for loading javascript files: http://codex.wordpress.org/Function_Reference/wp_enqueue_script the last argument takes either true or false to load in the footer
If you’re just using a small script or other markup, you can hook a function to the wp_footer filter, which should be included in all properly-coded themes: add_action( ‘wp_footer’, function () { ?> <script language=”javascript” type=”text/javascript”> startcart() </script> <?php } ); However, if your JavaScript code is more substantial, or you wish to use built-in … Read more
EDIT : use wp_enqueue_script as you want (enqueue in header or footer after jQuery as you want) to enqueue file called something like : gmap.js included in your plugin wp_enqueue_script(‘custom-gmap’, plugin_dir_url( __FILE__ ).’inc/js/gmap.js’, array(‘jquery’), false, true);//just change your path and name of file write this in your Js file 🙂 $(document).ready(function() { if (typeof google … Read more
You should be loading jQuery with wp_enqueue_script(‘jquery’) – that way, you won’t end up with multiple instances if plugins try to load it too. To use Google CDN, place this in your functions.php; wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js’, null, // Dependencies – none null // Version – use null to prevent WP adding version … Read more
The global variable tinyMCE has an array of editors. So you have to call the undoManager inside them. Like this for default wp editor on post edit/create screen: tinyMCE.editors[0].undoManager.clear(); If you want to do it in a specific editor, select the editor id in n like this: var n = 0; // editor id tinyMCE.editors[n].undoManager.clear();
To register scripts/styles conditionally if the page has a certain block you can follow the solution that @Will posted in the comments from a similar question. Copy/pasting with some modifications from that question: add_action( ‘enqueue_block_assets’, ‘myplugin_enqueue_if_block_is_present’ ); // Can only be loaded in the footer // add_action( ‘wp_enqueue_scripts’, ‘myplugin_enqueue_if_block_is_present’ ); // Can be loaded in … Read more
Well, I found the answer myself. I hope it helps others: I replaced both instances of: if ( selected ) { selection.add( wp.media.attachment( selected ) ); } with: selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] ); Apparently, the reset() function can be used to empty an array and then add elements to … Read more
When you take a look at the source of wp_enqueue_scripts() (or the register-sister), then you’ll see that there’s the global $wp_scripts handling all the heavy stuff. Basically the global is just an instance of WP_Scripts, which is a child of WP_Dependency and you can use all the magic from there if there’s no higher level … Read more
It looks like you are trying to send a POST request to the /istermactive endpoint, is that correct? (I think you may want to remove the trailing slash from the endpoint?) I’m not really sure the wp-api client is the right tool for a standard ajax POST, you may want to use jQuery.ajax or use … Read more
It’s been a while since this question was asked, but on the off chance that you are still looking for a solution: items_frame = wp.media.frames.items = wp.media({ title: ‘Add to Gallery’, button: { text: ‘Select’ }, library: { type: [ ‘video’, ‘image’ ] }, });