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

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

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

Unexpected script loading order

Simple Fix The reason why your code does not work is because the third parameter of the wp_enqueue_script() function is expecting an array, not a string. Just replace ‘footer-js’ with array(‘footer-js’) and it will work: function tallulah_scripts() { wp_enqueue_script( ‘header-js’, get_template_directory_uri() . ‘/js/header.min.js’, null, ‘1.0’, false ); wp_deregister_script(‘jquery’); wp_enqueue_script( ‘footer-js’, get_template_directory_uri() . ‘/js/footer.min.js’, null, ‘1.0’, … Read more