Support » Themes and Templates » wp_register_script putting script in header not working

  • Hi,

    I have a site that was running WordPress 4.1.4 and working fine. After updating to WordPress 4.2.1 some functions have stopped working. I have narrowed the problem down to jQuery not being loaded in the head, but instead being added in the footer.

    Before the upgrade jQuery was being loaded in the head, not it no longer is. The code to register the script in the theme has not changed, but the code no longer works. Theme has not been updated.

    This is the code that is being used:

    function vnc2015_enqueues()
    {
    	if( !is_admin()){
    			$url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js';
    			$test_url = @fopen($url,'r');
    			if($test_url !== false) {
    					wp_deregister_script('jquery');
    					wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', false, '1.11.1', false);
    					wp_enqueue_script('jquery');
    			} else {
    					wp_deregister_script('jquery');
    					wp_register_script('jquery', get_bloginfo('template_url').'/js/jquery-1.11.1.min.js', __FILE__, false, '1.11.1', false);
    					wp_enqueue_script('jquery');
    			}
    	}
    }
    add_action('wp_enqueue_scripts', 'vnc2015_enqueues', 100);

    I also tried changing to 1.11.2 of jQuery but that didn’t make a difference.

    Was something changed in the wp_register_script function on how/where scripts are loaded?

    Any ideas how to get the script to load in the head now?

    Thank you for your help.

  • The topic ‘wp_register_script putting script in header not working’ is closed to new replies.