[resolved] Unable to enqueue jQuery (2 posts)

  1. CGAdmin
    Posted 3 years ago #

    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() {
    	get_template_directory_uri() . '/js/login.js',
    	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("ul.tabs_login li:first").addClass("active_login").show();
    	jQuery("ul.tabs_login li").click(function() {
    		jQuery("ul.tabs_login li").removeClass("active_login");
    		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?

  2. CGAdmin
    Posted 3 years ago #

    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 http://mysite.com/child/ and the JS file is located at http://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',

Topic Closed

This topic has been closed to new replies.

About this Topic