ThemeShaper Forums » Thematic

[closed]

Move Javascript after footer

(8 posts)
  • Started 12 years ago by devzonefr
  • Latest reply from davidostrow
  • This topic is not resolved
  1. Hi !

    I'm trying to make some optimisations with javascript's files

    First I prefer to user Google Api for jquery :

    // smart jquery inclusion
    // & move javascript to footer
    if (!is_admin()) {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false );
    wp_enqueue_script( 'jquery' );
    }

    Second, and it's my problem, i want to move others files (hoverIntent, superfish, ...) in wp_footer().
    I've this code but i don't know how to use it with the thematic_head_scripts()...

    remove_action( 'wp_head', 'wp_print_scripts' );
    remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
    remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
    add_action( 'wp_footer', 'wp_print_scripts', 5 );
    add_action( 'wp_footer', 'wp_enqueue_scripts', 5 );
    add_action( 'wp_footer', 'wp_print_head_scripts', 5 );

    Thks

    Posted 12 years ago #
  2. madfatter
    Member

    Hi,

    I'm interested in how to do this as well. I've used the code above to successfully move the default WordPress scripts to the footer but I'm not sure where the actions are that add thematic's scripts to the head. Any help would be greatly appreciated.

    Thanks!

    Posted 12 years ago #
  3. madfatter
    Member

    I'm half way there:


    add_action('wp_footer','thematic_head_scripts');

    Adds the scripts to the footer but


    remove_action('wp_head','thematic_head_scripts');

    Does not take them out of the head.

    Does anybody know what I'm doing wrong?

    Thanks

    Posted 12 years ago #
  4. madfatter
    Member

    I figured it out. I needed to call the remove action on init.

    I'm posting the complete code for others who might want to do the same:


    //Remove the necessary actions from the head

    remove_action('wp_head', 'wp_print_scripts');
    remove_action('wp_head', 'wp_print_head_scripts', 9);
    remove_action('wp_head', 'wp_enqueue_scripts', 1);

    function my_remove_thematic_scripts() {
    remove_action('wp_head','thematic_head_scripts');
    }

    add_action('init', 'my_remove_thematic_scripts'); //wait for init

    //Add the actions to the footer

    add_action('wp_footer', 'wp_print_scripts', 5);
    add_action('wp_footer', 'wp_enqueue_scripts', 5);
    add_action('wp_footer','thematic_head_scripts');
    add_action('wp_footer', 'wp_print_head_scripts', 5);

    Posted 12 years ago #
  5. OK. I am really baffled. I tried the fix above and got the same result as the Javascript footer plugin for wordpress. Here is what is going on. I want to move JS to the footer. the js plug does that well, as does the code above, but it somehow is interfering with the nextgengallery slideshow feature. It uses the jw...imagerotator. I dont quite get how the code in the post breaks the rotator. here is what happens. If I leave it as you have put it, or if i jsut teh js footer code (almost the same) it breaks the rotator. If I comment out the second line of your code or the same line the rotator works, but the js does not move. I am sure this is a simple thing that i am missing. Right now it is set so the image rotator works. If you want I can set up my sandbox site to have this problem so my main site is not "broken"

    Let me know your thoughts.

    Thanks

    dave

    Posted 12 years ago #
  6. madfatter
    Member

    Hi davidostrow,

    I'm not particularly savvy at coding so I don't have much to offer in assistance. Could the issue involve the order in which the scripts are being placed in the footer? For instance, if some plugins are loaded before the jquery library it could break things. You may have already considered this...

    Posted 12 years ago #
  7. kirkroberts
    Member

    Thanks, madfatter! I used your code to move my js successfully. Very helpful!

    Posted 12 years ago #
  8. kirkroberts,

    I has the same issue as you. how did you fix the problem....

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.