Forums

[resolved] moving scripts from header (4 posts)

  1. spstieng
    Member
    Posted 3 years ago #

    I've added a few plugsins like SimplwViewer, Google Calendar and Image manager. When I looking at the HTML source, I discovered a lot of javascripts.

    Having a lot of javascripts in the header is not good if you want to optimize the site for the search engines.

    This code <?php wp_head(); ?> generates a lot of code, and most taken from plugins.

    How can I alter this to have the <scripts> be displayed in the footer rather in the header?

    I have looked into general-template.php to see if I could discover anything. The only thing I found was this:

    function get_header() {
    	do_action( 'get_header' );
    	if ( file_exists( TEMPLATEPATH . '/header.php') )
    		load_template( TEMPLATEPATH . '/header.php');
    	else
    		load_template( ABSPATH . 'wp-content/themes/default/header.php');
    }

    Any suggestions anyone?

  2. Xamataca
    Member
    Posted 3 years ago #

    This has to do with plugins inserting their needed javascript to work.
    And the correct placement is between your <head> tags in header.php if they are linking to a .js file

    Most won't work if you put them in the footer.php, because the js scripts need to set vars and functions before call them inside the <body> tags. Another matter is if those plugins just fill the head with javascript code... I think that's a problem with how the plugin is coded.

    I'm not an expert in JS but probably you will get a proper explanation from someone with more knowledge.

  3. spstieng
    Member
    Posted 3 years ago #

    Yeah, call to .js scripts needs to be in the header.
    But actual javascripts should be put in the footer if possible.

    I'll leave it be for the moment.

    Thanks.

  4. whooami
    Member
    Posted 3 years ago #

    Having a lot of javascripts in the header is not good if you want to optimize the site for the search engines.

    ...that's crap.

Topic Closed

This topic has been closed to new replies.

About this Topic