Grow your CSS skills. Land your dream job.

js in WordPress

  • # June 20, 2012 at 3:56 pm

    OK, I was having this issues in another thread, but I didn’t really know how to ask the right question. I figured out my beef with scripts and plug-ins that are not specially made for WP. Many times it requires a block of js code in the HTML file…right? And for some reason, for me, that seems to screw things up. The answer I guess would be to put it in the functions.php file, but I can never seem to touch that file without screwing it up.

    # June 20, 2012 at 4:05 pm

    I’m wondering how your theme is set up? Only in very rare circumstances should you be inserting JS through a Post or Page. You should be editing your theme (most likely the header.php) to include JS files.

    # June 20, 2012 at 4:17 pm

    not in a post/page…Sometimes you need to enter script tags in the header.php file and then add a block of code (even though it’s already linking to an external js file) in the head tag or right after the footer tage. Does that make sense?
    I was doing that a lot when I was building site with Dreamweaver.

    # June 20, 2012 at 5:12 pm

    Totally makes sense.

    Can you give an example of what you’ve tried that has screwed something up?

    # June 20, 2012 at 6:11 pm

    I was trying to use this plug-in for a Dynamic Grid Layout.

    http://www.wookmark.com/jquery-plugin

    https://github.com/GBKS/Wookmark-jQuery

    # June 20, 2012 at 6:17 pm

    It looks pretty simple, how are you including it in your theme files?

    # June 20, 2012 at 7:11 pm

    I entered the external js in a script tag in the head, and then that block of code at the bottom, right before the closing body tag….that’s the way they have it in their example. It didn’t work. Could it have been conflicting with something in the functions.php file? I’m not touching that. When it comes to js I only copy and paste.

    I have since found a WP plugin for this behavior, but would still like to know how to deal with these non-WP plug-ins.

    # June 20, 2012 at 8:18 pm

    This line:

    Needs to go after you include jQuery – sounds like you might have accidentally been putting it before.

    # June 24, 2012 at 4:24 pm

    I made sure the script tags were in order and still couldn’t get it to work.

    One script I am trying to use requires a block of js in the head tag and another right before the closing body tag. I have a feeling it’s just too easy to have conflicts??

    I tried putting them the theme .php files, I also found a few wordpress plug-ins that allow custom js and css per page and it’s still not working.

    Anyway, thanks for trying to help

    # June 24, 2012 at 8:49 pm

    if you are including js files into wordpress, you should be using wp_enqueue_script in your functions.php file. You could even take it a step further and use conditionals for your page

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    http://codex.wordpress.org/Conditional_Tags

    # June 24, 2012 at 9:19 pm

    that’s the thing…everytime I try to do anything to the functions.php file I screw it up.
    I’d rather not touch it

    # June 24, 2012 at 9:26 pm

    if you are not using wp_enqueue_script to include your scripts then you are doing it wrong. Just make a backup copy of the functions.php file that way if you screw it up, you can always fix it. Not using the wp_enqueue_script can mess up other plugins. There is a reason the function does exist. If you are going to mess with WordPress, then you must get comfortable messing with the functions.php. Just go all the way to the bottom of the file and start your custom stuff.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".