Using jquery with wordpress using wp_enqueue_scripts

It sounds like your template is missing a call to wp_head() which will output your enqueued scripts and styles. You’d normally place wp_head() in your header.php template and include this in your page template. To conditionally enqueue jQuery based on the page template being used you could use the following code: add_action( ‘wp_enqueue_scripts’, ‘custom_theme_load_scripts’ ); … Read more

Using function from enqueued .js file in theme in plugin?

Yes. Dependencies work across all of WP, it doesn’t matter where you enqueue your script. All that matters is that you define your dependencies correctly, and you’re doing that. If, however, you plan to publish both the theme and the plugin as standalone versions, you shouldn’t rely on your plugin being used with your theme, … Read more

Get uploaded image and attach it to the new post

You have to use the javascript FormData object to upload files via ajax. A simple tutorial is provided here. In PHP the file will be available via the globals $_FILES and $_POST. Additional to the tutorial the WordPress specific data “action” (and maybe “nonce”) have to be added to the formData object: formData.append(‘action’, ‘add_your_action_here’); // … Read more

Where is this JQuery coming from?

I understand that this loads JQuery throughout my website – but here’s the odd thing, if I change the version of JQuery is does NOT update. It’s not odd. You can’t load arbitrary versions of jQuery by changing the version argument. From the documentation for wp_enqueue_script(), that version number is: String specifying script version number, … Read more

Loading jquery locally

Although it seems like you should be able to just call the function and have it load the script, it’s slightly more complicated. Instead, scripts need to be registered and enqueued inside a hook, so they’re loaded in the right order. To get jQuery loaded on the front end of your theme wrap the function … Read more

Output votes to div dynamically in wordpress

[EDIT] Provided better replacements. Try this: In template.php, replace: echo ‘<div id=”vote_counter”>’. $votes.'</div><br>’; ..with: echo ‘<div id=”vote_counter-‘ . $post->ID . ‘” class=”vote_counter”>’. $votes.'</div><br>’; In voteme.js, replace: jQuery(“#vote_counter”).html(response.vote_count); ..with: jQuery(“#vote_counter-” + post_id).html(response.vote_count); You should also declare post_id and nonce as local variables; i.e.: var post_id = $(this).attr(“data-post_id”), nonce = $(this).attr(“data-nonce”); Hope that helps.

why is my wordpress Jquery-Ajax call not working?

You need to change the data that you are sending in the ajax request. For ajax to work in WordPress you need to send the action variable in ajax post request. Change data: {package: package}, to data: {action: ‘ajaxAutopopulate’, package: package} Also you can use the wordpress default function wp_send_json( $response ) for encoding of … Read more