• I know this has been asked about a million times. I’ve searched and gone through guides and instructions on how to do this for days and I’m clearly still doing something wrong. My jquery just won’t work. I’ve tried following instructions for registering and enqueueing the scripts, and instructions for wrapping the jquery, etc. Nothing seems to help. So I’m hoping that if I show you my code for enqueueing the script, you can tell me what is wrong. I’ve tried several different instructions for enqueueing it and apparently, I just can’t wrap my brain around it.

    Here is my code:

    function duckstyles()
    {
    wp_enqueue_style( ‘style’, get_template_directory_uri() . ‘/style.css’ );
    wp_register_script( ‘duckapp’, get_template_directory_uri() . ‘/duckapp.js’, __FILE__, array( ‘jquery’ ), 1.0, true);
    wp_enqueue_script( ‘duckapp’, get_template_directory_uri() . ‘/duckapp.js’, __FILE__, array( ‘jquery’ ), 1.0, true);
    }
    add_action( ‘wp_enqueue_scripts’, ‘duckstyles’ );

    my js file is located in the same directory as the functions.php file, the main theme directory. The CSS works. The only javascript I have for the wordpress page is a script that changes the header’s class when you scroll down on the page. It worked fine before I started trying to enqueue the scripts. I feel bad asking about something that has been posted so many times, but apparently I lack the ability to follow the instructions in the various websites and other posts. :/

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Can you post a link to a page that shows the issue?

    Thread Starter continuumcomplex

    (@continuumcomplex)

    Sure. This is just a free-host page that I have to experiment with building custom themes. Trying to learn more about wordpress and such. The only javascript on the page is on the scroll action, when you scroll down the header class changes. I’ve been playing with both the enqueue and the jquery to try and make sure which is the issue. I mainly want to know if the above enqueue script looks correct or not. If it is correct, then I’ll have to figure out what else is causing the problem. I have seen some browser errors with loading the jquery, first identifying $ which I then changed to just say jquery (as instructed on several jquery noconflict wrap pages, and now it just seems to have an issue identifying that. -.- Either way, it’s weird to be a jquery issue since it was working before I started messing with the enqueueing – though I won’t admit it’s entirely possible I messed up the jquery while trying to set up enqueueing and maybe got the enqueueing correct but now have messed up my jquery. ha. Again, that’s why I primarily want to know if my enqueue script above seems correct.

    Thanks!

    First, you don’t need that stray __FILE__ in there. It’s messing up the order of the arguments. You also don’t need to pass all those arguments to wp_enqueue_script() if you’ve already registered the script via wp_register_script(), as you’ve done.

    wp_register_script( 'duckapp', get_template_directory_uri() . '/duckapp.js', array( 'jquery' ), '1.0', true);
    wp_enqueue_script( 'duckapp' );
    Thread Starter continuumcomplex

    (@continuumcomplex)

    Changed it to:

    function duckstyles()
    {
    wp_enqueue_style( ‘style’, get_template_directory_uri() . ‘/style.css’ );
    wp_register_script( ‘duckapp’, get_template_directory_uri() . ‘/duckapp.js’, array( ‘jquery’ ), 1.0, true);
    wp_enqueue_script( ‘duckapp’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘duckstyles’ );

    Thanks, it’s still not working. Does that look correct? If so, I’ll still digging into my jquery and see if I somehow messed up that when messing with everything else!

    Your PHP code looks fine. In your previous post, you mentioned that you had fixed any potential noConflict issues, so that should be fine as well. Would it be possible to throw up a temporary site so I can see what’s going on?

    Thread Starter continuumcomplex

    (@continuumcomplex)

    That’s weird, I could have sworn I linked it above but the link isn’t there. This is the basic wordpress page that I’ve been experimenting with. (WordPress Page).

    When you scroll down, the header should change class and get smaller. Looking at it with inspect element, I can see the network pulling in my js file, the right stylesheet, jquery, etc.

    The jquery adds the .fixed class onto the #header div and adds the .navfixed class onto the nav UL, removing the .nav class. It worked fine before I started trying to change things to fit better with recommended wordpress code. :/

    What’s happening here is that your entire JavaScript is wrapped in a function main, starting from line 3, but you never actually call this function, so the code never gets executed. If you delete the lines that wrap the function:

    3: var main = function() {
    48: };

    you should be good to go.

    Thread Starter continuumcomplex

    (@continuumcomplex)

    Uuugh, it’s always something absurdly simple. lol. I was calling it from the page and then removed that when I started setting up the enqueueing script. That makes sense. -.- Thanks, it’s working now!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Enqueue scripts – again’ is closed to new replies.