• Resolved josh-jones

    (@josh-jones)


    Has anyone else run into an issue where when using wp_enqueue_script() in a plugin, instead of it using the version number you define, it decides to use the wordpress version number that’s installed?

    It only seems to happen with wp_enqueue_script() and not with wp_enqueue_style() and I can’t figure out why…

    I don’t actually put the version number itself in the wp_enqueue_script() call, rather, I use a constant that I’ve defined in the beginning of the plugin… It works perfectly in wp_enqueue_style(), but fails miserably in wp_enqueue_script()

Viewing 7 replies - 1 through 7 (of 7 total)
  • Could you please provide the related pieces of code so i(or anyone else) can try to replicate the problem.

    I use that function for handling some theme stuff and don’t have this issue, so i’d be curious to see if i can replicate it, but i’ll need some idea of your code usage before i can do that.

    Thread Starter josh-jones

    (@josh-jones)

    Sure thing…

    Here’s where I define the constant in the main plugin file:

    // Define a couple of constants
    define('SEXY_OPTIONS','SexyBookmarks');
    define('SEXY_vNum','3.1');

    And here is where I use wp_enque_script() and wp_enqueue_style() in the public.php file which handles everything seen on the front end:

    // Write the <head> code only on pages that the menu is set to display
    function sexy_publicStyles() {
    	global $sexy_plugopts, $post, $sexy_custom_sprite;
    
    	// If custom field is set, do not display sexybookmarks
    	if(get_post_meta($post->ID, 'Hide SexyBookmarks')) {
    		echo "\n\n".'<!-- '.__('SexyBookmarks has been disabled on this page', 'sexybookmarks').' -->'."\n\n";
    	} else {
    		//custom mods rule over custom css
    		$surl = (!is_null($sexy_custom_sprite)) ? $sexy_custom_sprite : SEXY_PLUGPATH.'css/style.css'; // If custom css, generated by sprite
    		$surl = ($sexy_plugopts['custom-mods'] == 'yes') ? WP_CONTENT_URL.'/sexy-mods/css/style.css' : $surl; // If custom mods option is selected, pull files from new location
    		wp_enqueue_style('sexy-bookmarks', $surl, false, SEXY_vNum, 'all');
    	}
    }
    function sexy_publicScripts() {
    	global $sexy_plugopts, $post;
    
    	if (($sexy_plugopts['expand'] || $sexy_plugopts['autocenter'] || $sexy_plugopts['targetopt']=='_blank') && !get_post_meta($post->ID, 'Hide SexyBookmarks')) { // If any javascript dependent options are selected, load the scripts
    		$surl = ($sexy_plugopts['custom-mods'] == 'yes') ? WP_CONTENT_URL.'/sexy-mods/' : SEXY_PLUGPATH; // If custom mods option is selected, pull files from new location
    		$jquery = ($sexy_plugopts['doNotIncludeJQuery'] != '1') ? array('jquery') : array(); // If jQuery compatibility fix is not selected, go ahead and load jQuery
    		$infooter = ($sexy_plugopts['scriptInFooter'] == '1') ? true : false;
    		wp_enqueue_script('sexy-bookmarks-public-js', $surl.'js/sexy-bookmarks-public.js', $jquery, SEXY_vNum, $infooter);
    	}
    }
    
    add_action('wp_print_styles', 'sexy_publicStyles');
    add_action('wp_print_scripts', 'sexy_publicScripts');
    add_filter('the_content', 'sexy_position_menu');

    I’ll go give it a shot… give me a few mins..

    Seems to work fine here…

    I see 3.1 in the output (also tried 2 other values to be sure), bearing in mind i’m testing under WP 3.0, so perhaps that makes a difference, i don’t have a 2.9 install to test against at the moment.

    Tested the code on 2 seperate wp_enqueue_script calls, and was unable to reproduce the problem, the correct version is output in the source of the page.

    Thread Starter josh-jones

    (@josh-jones)

    Nevermind, I think it’s a plugin conflict of some sort… I just tested it on a test blog with NO other plugins activated, and it works perfectly as it should.

    Thanks for looking into it though!

    No problem, you’re welcome… ??

    I’m having the same problem. I’m trying to re-register jQuery using google’s CDN, but the WP version number is getting appended to the end of the URL and so I’m afraid I’m losing out on the cache benefit. The code is very simple, here’s my functions.php file:

    <?php
    function bowdenInit() {
    	if(!(is_admin())) {
    		wp_deregister_script('jquery');
    		wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"), false, false);
    		wp_enqueue_script('jquery');
    
    		wp_enqueue_script('cycleLite', (get_bloginfo('template_url')."/js/jquery.cycle.lite.min.js"), array('jquery'), '1.0');
    		wp_enqueue_script('validate', ("https://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"), array('jquery'), false);
    	}
    }
    
    add_action('init', 'bowdenInit');
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp_enqueue_script() using WP version number?’ is closed to new replies.