Include jQuery plugin in WordPress

A better method is to use the built in WordPress hooks in your functions.php with conditionals if needed ( for instance to load it only on certain pages). For hooking into admin you can use admin_print_scripts for hooking into the front you can use wp_print_scripts or one of the many other action hooks. For example: … Read more

Best way to include jQuery and fire with script at bottom of container

You typically should use the jQuery version that’s built in. There are instances where you might want to use wp_dequeue_script(‘jquery’) and then add a different version of jQuery. Here’s the best way to add a script dependent on jQuery: function theme_register_scripts(){ wp_enqueue_script(‘jquery’); wp_enqueue_script(‘myscript-name’, get_bloginfo(‘stylesheet_directory’) . ‘/js/myscript.js’, array(‘jquery’)); } add_action(‘wp_print_scripts’, ‘theme_register_scripts’); The third argument of wp_enqueue_script … Read more

Combining media queries with image sizes

First off, kudos to this pretty cool solution. I think you’re on the right track and not sure how much more you could do. You could certainly replicate the above with PHP & CSS, thus not requiring jQuery. It would require you to have an array of your sizes and just loop through them. This … Read more

Not sure why wp_ajax isn’t working?

This is just a simple javascript issue. When your javascript that attaches the click behavior to the form is parsed, the form element doesn’t yet exist because it’s further down the page, so it doesn’t get attached. Either move the javascript below the form, wrap it in a jQuery(document).ready(), or use live. EDIT – $(‘#ajaxForms’).serialize(); … Read more

WP_enqueue_script() loads them always in wp_footer()?

All of these scripts are already registered to print in the footer. See wp-includes/script-loader.php for details. When you try to register the scripts again WordPress doesn’t change that. The workaround would be to register a new script for wp_head with those scripts as dependencies (the third parameter of wp_enqueue_script()). Do not register the scripts in … Read more

Script for initializing JQuery Masonry for WordPress

This executes, when the DOM has been constructed, before all content has been loaded $(document).ready(function(){ … }); $(function(){…}); // short form This executes, when all content has been loaded $(window).load(function(){ … }); This executes immediately, when it is first encountered by the browser (function(){ … })(); The latter is known as a self-executing anonymous function, … Read more