Cannot get Jquery to work with wordpress

I don’t think you have to register jquery. I just put this in my functions.php: function my_scripts_method() { wp_enqueue_script( ‘main’, get_template_directory_uri() . ‘/js/main.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ ); It includes my custom scripts that are reliant on jquery.

jquery does’t work

The answer is obvious. The jQuery is loaded in noConflict mode. It means that the global $ shortcut for jQuery is not available. You have to use closure, like this: (function($) { $(document).ready(function() { $(‘#slider’).coinslider({ width: 948, height: 367 }); }); })(jQuery); In addition I would like to recommend you to create hook handler for … Read more

AJAX – Returning Two JSON Objects with One PHP Function

If I get it correctly, You need to wrap them in an array and pass to Javascript. function get_ldap_attr() { header(“Content-type: application/json”); … // suppose you want to return $second_var echo json_encode(array($sup,$second_var)); die(); } Success function of JSON request will receive them as array. You can access them with integer index. jQuery(function() { jQuery(‘#empLanId’).on(‘blur’, function() … Read more

How can i display a jquery slide on front page

As Jerome mentioned in his comment, including your own version of jQuery via a script tag is wrong. Nextgen adds the WordPress supplied version correctly via wp_enqueue_script, which creates the conflict. Remove the inclusion of jQuery via script tag. Properly enqueue your other javascript files with jQuery as a dependency. Fix your jQuery code to … Read more

Problem passing id-specific objects to javascript via wp_localize_script

In your code playerId is a string. So playerId.tracks can’t work. So you can create a multidimensional array with wp_localize_script (WP 3.3+): $playlists = array( ‘playlist150’ => array( ‘tracks’=> array(‘track1’, ‘track2’) ), ‘playlist257’ => array( ‘tracks’=> array(‘track3’, ‘track4’) ) ); wp_localize_script( ‘some_handle’, ‘allPlaylists’, $playlists ); Then in the js use the bracket notation to retrieve … Read more

jquery & ajax sending data to php

First of all, your js is wrong, you are mixing the syntax of jQuery.post() and of jQuery.ajax() You should use jQuery.ajax({ type: “POST”, url: ajaxurl, data: { action: “lu_ajax”, status: “enabled” }, success: function( data ) { alert(data); } }); or jQuery.post( ajaxurl, { action: “lu_ajax”, status: “enabled” }, function(data) { alert(data); } ); After … Read more

How to use jquery included with wordpress for jpanelmenu

To use the WordPress-bundled version, simply stop de-registering it and replacing it with the Google version. function wpa_132328_enqueue_scripts(){ if ( !is_admin() ) { // jQuery wp_enqueue_script(‘jquery’); // load jPanelMenu wp_enqueue_script(‘jpanelmenu’, get_bloginfo(‘template_directory’) . “/js/jquery.jpanelmenu.js”); } } add_action( ‘wp_enqueue_scripts’, ‘wpa_132328_enqueue_scripts’ ); “$ is not defined” errors means you aren’t in noconflict mode. Adjust your code as follows: … Read more

Load random posts without refreshing page (jQuery)?

I’ve been playing with ajax for the past couple days – I like to go the hook route so first lets set up our ajax call: $(‘#buttonID’).click(function(){ $.ajax({ url: ‘/wp-admin/admin-ajax.php’, type: ‘GET’, data: { ‘action’ : ‘implement_ajax’ }, dataType: ‘html’ }) .success(function(results){ $(‘#ContentWrapper’).html(results); }) .fail(function( jqXHR, textStatus ) { console.log( “Request failed: ” + textStatus … Read more