jQuery don’t working

Don’t load jQuery that way. It comes built into WordPress, so what you really want to do is tell WordPress that (1) your Javascript file should be loaded, and (2) it relies on jQuery being loaded. You do this with wp_enqueue_script. So put this in your functions.php file, replacing the path in quotes with the … Read more

calling function in external js file

i think the script.js file is not loading properly. if its loading then the function should work as expected. are you referencing the complete path of script in your script.js call? like <script type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/256287/some-domain.com/path/widget.js”></script> try opening that file from page source and see if its loading the correct js file? its always best practice … Read more

WordPress jQuery crash [closed]

The reason you are getting the error is that you are trying to bind a JavaScript function to a WordPress PHP hook. Bind your JavaScript handler to the form’s submit event: $( “#your-form” ).submit(function( event ) { //Select checkboxes by id var $checkboxes = $(‘input[id=checkboxprice]’); //Set event $checkboxes.on(‘change’, function () { var totalPrice = 0; … Read more

How to call custom jQuery plugins into the customizer controls

First, in order to enqueue JS in the customizer controls, you need to use the customize_controls_enqueue_scripts action. This is different than the action used to enqueue scripts into the customizer preview, which is what themes normally do via customize_preview_init or wp_enqueue_scripts. So in your snippet above, replace customize_preview_init with customize_controls_enqueue_scripts. Secondly, in order to extend … Read more

Can’t delete the default jQuery in the theme

An example on how to deregister a WordPress built-in library and load your own: function load_custom_scripts() { wp_deregister_script( ‘jquery’ ); wp_register_script(‘jquery’, ‘//code.jquery.com/jquery-2.2.4.min.js’, array(), ‘2.2.4’, true); // true will place script in the footer wp_enqueue_script( ‘jquery’ ); } if(!is_admin()) { add_action(‘wp_enqueue_scripts’, ‘load_custom_scripts’, 99); }

How to add post thumbnail dynamically using Jquery?

js (edit 4) $(function() { $(‘body’).on(‘click’, ‘.post-link’, function() { // Jquery var ajax = {}; ajax.id= $(this).attr(‘rel’); var ajaxurl=”/wp-admin/admin-ajax.php”; jQuery.post( ajaxurl, { ‘action’: ‘get_img_post_and_title’, ‘data’: ajax }, function(response){ // add html if(response.success){ $(‘#post-cont’).append(“<li>ID: “+response.data.post_id+” “+response.data.post_title+” <img src=””+response.data.post_thumb+””/> –<a href=”#” class=”close”>X</a></li>”); } } ); }); }); php (edit 4) // php add_action(“wp_ajax_get_img_post_and_title”, “get_img_post_and_title”); add_action(“wp_ajax_nopriv_get_img_post_and_title”, “get_img_post_and_title”); function … Read more