• Resolved DesignLoud

    (@designloud)


    Hi, I am developing a custom theme from a static site I created (everything works fine on static site) but when I include the scripts in my header.php and check functionality I lose all my functionality. I may not be entering the script in the way that WordPress prefers. Ultimately because this is a theme I am developing for a client I also need the php for wordpress to get the theme directory to pick up those scripts. Because I may have confused you here is the link to the sample theme: http://itestwebpageshere.biz

    Currently instead of using something like
    <script> src="<?php template_directory ('/js/name_of_script.js') ?></script>

    I know the above is not the correct php but I cant remember what I tried via the forums but it didnt work anyways so I tried to use the full url to those files in the header.php. Only for it to still not work

    So in a nutshell: Why isnt my Javascript and Jquery working for the animation I want to use in the nav menu (simple fade on image on mouse hover, etc.) & how will I effectively tell wordpress to get the Template url /js/my-scripts.js?

    Hoping someone with some knowledge with theme development and a little Jquery background can help me troubleshoot this to get it to work like it does in my static mockup.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I may not be entering the script in the way that WordPress prefers.

    You need to use wp_enqueue_script.

    Thread Starter DesignLoud

    (@designloud)

    ok so Im giving this a shot (excuse the noviceness of my php) but is this what I would enter in my functions.php?
    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    I guess I would put my custom js in my header.php along with the link to googles jquery library?

    This is what it looks like in my static html page (works fine)

    [Ditto]

    and of course for convenience purpose and trouble shooting here is the static link (roughly compiled):
    http://itestwebpageshere.biz/Untitled-4.html

    Thread Starter DesignLoud

    (@designloud)

    Bummer, it stripped my code I was asking about, let me try this again meeting their rules:

    <?php function my_custom_menu_script() {
    	wp_enqueue_script(
    		'jquery-1.2.6.min',
    		get_template_directory_uri() . '/js/jquery-1.2.6.min.js',
    		array('jquery')
    	);
    }
    add_action('wp_enqueue_scripts', 'my_custom_menu_script'); ?>

    And I guess I would repeat that process but with a different function name for the other js file. Then please see my comment from the previous post.

    Thread Starter DesignLoud

    (@designloud)

    I fixed this issue and I can see what esmi was trying to say.. Unfortunately I am not very bright 😉 so I needed someone outside of the wordpress codex to explain this to me but for future people who will be looking for this here is how I fixed it:

    http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Registering Jquery and Javascript in the header’ is closed to new replies.