views:

127

answers:

2

I set my wordpress permalink structure to /%postname%/ but now when I go to a page other than the home page (for example if I went to somelink.com/about) I lose all javascript references.

I think this happens because the links to the js files are no longer right as it is in the imaginary folder "about". This is how the js files are referenced in the header.php file.

        <script type="text/javascript" src="wp-content/themes/default/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/cufon-yui.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/Goudy_Bookletter_1911_400.font.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {      
            Cufon.replace('h1');
            Cufon.replace('h3', {textShadow:'0 1px #fff'});
        });
    </script>

Am I doing something wrong?

A: 

I gather you are manually inserting the javascript calls, which is not the best way to handle jQuery inclusion in Wordpress - you should look into wp_enqueue_script, which will keep you from including the jquery libraries more than once if a plugin or theme you are using is also including them.

Also, the ay you have the source written, I believe you are correct - the client is looking for the js files in the relative path under /about. Place a "/" before wp-content to have the client look for them inside wp-content within your root directory (assuming WP is installed at root).

cori
I've been looking into the wp_enqueue_script. In fact maybe you can help me with something. How would I reference a script that I have locally? I want to reference the Cufon script wordpress doesn't have it included.
codedude
Look to the $src param, which directs wp's script loader to the url of the desired script, and the $depends param which tells WP what built-in scripts are required to be loaded *before* the custom script. See http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_script_depends_on_scriptaculous for an example based on scriptaculous.Also pay attention to the no-conflct wrapper information at http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers if you're familiar with jQuery outside of WP.
cori
+1  A: 

if you are referencing anything in your template files you can use either

1:

<?php bloginfo('url');?>

or 2:

<?php bloginfo('template_url');?>

which would be coded as:

<script type="text/javascript" src="<?php bloginfo('url');?>/wp-content/themes/default/js/jquery-1.4.2.min.js"</script>

or

<script type="text/javascript" src="<?php bloginfo('template_url');?>/js/jquery-1.4.2.min.js"</script>

1: loaded the main site URL; 2: will return the absolute url to your current themes directory,

(which is better for theme development).

Marty
Hey man! thanks a lot! This is exactly what I was looking for. I love how easy this is to use...thanks again
codedude
I agree that that's easier to drop into place then wp_enqueue_script. You still may end up loading jQuery more than once in your theme, especially if you're using plugins that use jQuery, but if that overhead's not important then this is a simpler way to handle it.
cori