• Resolved CGAdmin

    (@cgadmin)


    For one reason or another, I am unable to get my script to properly enqueue even though it works (nearly) perfectly embedded in the footer. The script is to allow for the overlapping/hiding of multiple pages on a small user login form on the header. I have attempted various versions of the following enqueue function:

    function my_scripts_method() {
    	wp_register_script('login_script',
    	get_template_directory_uri() . '/js/login.js',
    	array('jquery')
    	);
    	wp_enqueue_script('login_script'); }
    add_action('wp_enqueue_scripts', 'my_scripts_method');

    The login.js file is as follows:

    jQuery(document).ready(function() {
    	jQuery(".tab_content_login").hide();
    	jQuery("ul.tabs_login li:first").addClass("active_login").show();
    	jQuery(".tab_content_login:first").show();
    	jQuery("ul.tabs_login li").click(function() {
    		jQuery("ul.tabs_login li").removeClass("active_login");
    		jQuery(this).addClass("active_login");
    		jQuery(".tab_content_login").hide();
    		var activeTab = jQuery(this).find("a").attr("href");
    		if (jQuery.browser.msie) {jQuery(activeTab).show();}
    		else {jQuery(activeTab).show();}
    		return false;
    	});
    });

    As I mentioned, I am able to embed this same code in no conflict mode directly in the footer, but I would prefer to be able to keep these files as clean as possible.

    Am I performing the enqueue function incorrectly?

Viewing 1 replies (of 1 total)
  • Thread Starter CGAdmin

    (@cgadmin)

    I just got to thinking, the enqueue function references a JS file located at “/js/login.js”. We are creating a multisite network and have been doing much of the testing on one of the “child” sites. This means the function was looking in the wrong directory for the JS file since the architecture is set up as https://mysite.com/child/ and the JS file is located at https://mysite.com/js/login.js.

    For those with the same stupid hat on as me, be sure to include a “../” in front of url references when working with multisite installations! (Otherwise, the code is just fine.)

    New line in function should be:

    get_template_directory_uri() . '../js/login.js',

Viewing 1 replies (of 1 total)
  • The topic ‘Unable to enqueue jQuery’ is closed to new replies.