jquery won’t load in footer

I wanted to move jquery to the site’s footer, but that doesn’t work. I’ve tried it with the following code. As you can see, I have a couple of another scripts and they load correctly on the footer. Only jquery won’t work. //This adds our JavaScript Files function wel_adding_scripts() { wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js’, ”, ‘2.1.1’, … Read more

is_page() function doesnt working

I’m trying to add these custom CSS and JS (written inside a custom plugin) only add to a specific page. this is my code <?php function randomAlphaNumeric($length) { $pool = array_merge(range(0,9), range(‘a’, ‘z’),range(‘A’, ‘Z’)); $key=”; for($i=0; $i < $length; $i++) { $key .= $pool[mt_rand(0, count($pool) – 1)]; } return $key; } add_action(‘init’, ‘register_script’); function register_script(){ … Read more

Question about the way that wp_register_script works

Ok so I’m using the Roots Theme for WordPress (https://github.com/retlehs/roots), which, is sort of a starter theme or theme framework. I’m confused about the way that it deregisters the WordPress loaded version of jQuery and but it registers it again without specifying the exact location of the script. So in the header.php of the theme … Read more

Naming script handles right way

I was wondering is there any convention or what is the right way for naming handles in wp_register_script() and wp_register_style() functions? For example if I am developing a plugin that uses modernizer, is it better simply naming it ‘modernizer’ or something unique like ‘my-script-modernizer’? If it is better to have unique handles and I am … Read more

Using multiple versions of jQuery while still calling it like WP likes

I have two JS plugins inside my plugin. One uses jQuery 1.7.1 and the other 1.9.1. I need to have each of them use different version. This is how things are at the moment: Plugin php file: wp_register_script(‘jq-1.9.1-js’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js’); wp_enqueue_script(‘jq-1.9.1-js’); wp_register_script(‘jq-1.7.1-js’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js’); wp_enqueue_script(‘jq-1.7.1-js’); Plugin JS file: var $j = jQuery.noConflict(); $j(document).ready(function() { // plugin 1 … Read more

Register script version not showing

I want to implement cache busting on a specific script, but the version is not added to the url as query vars. Here is the code I’m using : wp_register_script( ‘custom’, get_stylesheet_directory_uri() . ‘/js/custom.min.js’, array(‘jquery’,’modernizr’), filemtime( get_stylesheet_directory().’/js/custom.min.js’ ), true ); I’m using the filemtime function to get the timestamp of the last modification as my … Read more

Can’t move jQuery to footer

Below two methods did not help me. My jQuery is always on the head section. What can be the reason? Method 1: (adding below code to function.php) if (!is_admin()) add_action(“wp_enqueue_scripts”, “my_jquery_enqueue”, 11); function my_jquery_enqueue() { wp_deregister_script(‘jquery’); wp_enqueue_script( ‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js’,array(),’1.9.0′,true); } this one works when I change ‘jquery’, to some other string as first parameter in … Read more

How resource intensive is wp_register_script()?

I’m trying to use the has_shortcode() function to only load certain scripts when there is a shortcode in the post’s content, with this code: wp_register_script( ‘shortcode-js-file’ , FILE_URI, array( ‘jquery’), ”, true ); if(isset($post->post_content) && has_shortcode($post->post_content, ‘shortcode_name’)) { wp_enqueue_script( ‘shortcode-js-file’); } So in the above code, I’m registering the script on all pages, whether there … Read more

Use js script from one plugin in another plugin

I have two plugins that work together (one is an add-on of sorts). In the “main” plugin, I have a js function in a file located like so: wp-plugins/main-plugin-name/js/main-js.js If my secondary plugin, I have another .js file located like so: wp-plugins/secondary-plugin-name/js/sec-js.js In this second plugin’s .js file, I want to use a function located … Read more

Help with enqueing scripts in footer after init action

In my functions.php, I have set a register_scripts() and load_scripts(), and hooked them to the ‘init’ action. I have registered all the scripts to be loaded in the footer, in order to optimize page load. Some of the scripts I’ve registered in register_scripts() are not enqueued in load_scripts() because I only want to load them … Read more