152 posts
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
partnuz says

According to the twentyten wordpress theme made by wordpress team you should

/* Always have wp_head() just before the closing * tag of your theme, or you will break many plugins, which * generally use this hook to add elements to <head> such * as styles, scripts, and meta tags. */ </head>

Yet If I do some my scripts cant load because I set their settings before wp_head is initialized. My question is how do you use wp_head() ? Are wordpress team developers wrong ?

438 posts
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

wp_head will effect the load order of scripts.

Any script you add to your header, if it’s before wp_head, will load before any scripts that are loaded via wp_head (functions.php etc..).

If you are loading your jquery from your functions.php and using a script in your header for something like a slider, you need to put that script after wp_head because you want jquery to load first.

Or something like that, I just make this stuff up as I go. :)

2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Why not try loading your scripts the right way? (keeping header.php cleaner too)


function di_js_registers() {
if(!is_admin) {
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"), false, '1.6.1', false); // last false sets it to load in the header
    wp_register_script('samplescript', ("http://sitename.com/wp-content/themes/mytheme/js/samplescript.js"), false, '1.0', false);
    wp_enqueue_script('jquery');
    wp_enqueue_script('samplescript'); }    
    if(is_page(17)) { 
    wp_register_script('contactpagejs', ("http://sitename.com/wp-content/themes/mytheme/js/contact.js"), 
        array('dependencies', 'here', 'samplescript', 'jquery'), '1.0', false); //depends on jquery and samplescript, so those get loaded first
    wp_enqueue_script('contactpagejs'); }
    }

add_action( 'wp_enqueue_scripts', 'di_js_registers' );
2002 posts
  • Has referred 50+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
bitfade says
digitalimpact said
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"), false, '1.6.1', false); // last false sets it to load in the header
the right way is to stick with jquery bundled with wordpress.
3264 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

keep your header.php clean…

head

<!DOCTYPE html SYSTEM>

<html &lt;?php language_attributes(); ?&gt;>
<head>
        <meta content="&lt;?php bloginfo('html_type'); ?&gt; charset=&lt;?php bloginfo('charset'); ?&gt;" http-equiv="Content-Type" />
        <title>&lt;?php bloginfo('name'); ?&gt; &lt;?php wp_title(); ?&gt;</title>
        <meta name="description" content="&lt;?php bloginfo('description'); ?&gt;" />

                 &lt;?php wp_head(); ?&gt;
</head>

functions.php

<?php add_action('after_setup_theme', 'homegrown_setup' );

function homegrown_setup()
{
    add_theme_support('automatic-feed-links');
    add_theme_support( 'post-thumbnails' );
    add_theme_support( 'menus' );
    add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );

}

add_action('template_redirect', 'homegrown_load_scripts');

function homegrown_load_scripts()
{
    if (is_admin())
    {
        return false;
    }

    if (!is_admin())
    {
        wp_enqueue_script( 'jquery' );

        if ( is_singular() and comments_open() and (get_option('thread_comments') == 1))
        {
            wp_enqueue_script( 'comment-reply' );
        }

    }
}
//Set Priority 1 to load before plugin styles
add_action( 'init', 'homegrown_load_styles', 1 );

function homegrown_load_styles()
{
    if (is_admin())
    {
        return false;
    }
        if (!is_admin())
    {
        wp_register_style( 'screen', get_bloginfo('stylesheet_url'), 1.0);
        wp_enqueue_style( 'screen' );
    }
?>
3264 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

The doc type isn’t spouse to have the SYSTEM in it forum is adding it for some reason…

PS: I still can’t edit posts

2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says
bitfade said
digitalimpact said
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"), false, '1.6.1', false); // last false sets it to load in the header
the right way is to stick with jquery bundled with wordpress.

True, that was just an example :)

However, I like to take advantage of Google’s popularity and serve a jQuery that people are most likely to have cached already (by visiting Gmail, for example) ;)

EDIT : @OrganicBeeMedia – I can edit posts. Something with your browser/dns cache maybe?

3264 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says
digitalimpact said
EDIT : @OrganicBeeMedia – I can edit posts. Something with your browser/dns cache maybe?

its been like this for Safari since they changed the buttons

EDIT : works fine in Chrome

214 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 6 years
  • Sells items exclusively on Envato Market
agusmu says
partnuz said
Yet If I do some my scripts cant load because I set their settings before wp_head is initialized. My question is how do you use wp_head() ? Are wordpress team developers wrong ?

Loading javascript using wp_enqueue is a must in review process today… If you insert your script directly to header.php either before or after wp_head, there is possibility for your theme to be soft rejected… ;)

438 posts
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says
Loading javascript using wp_enqueue is a must in review process today… If you insert your script directly to header.php either before or after wp_head, there is possibility for your theme to be soft rejected
wp_enqueue is the correct way to call a script but where you enqueue it from doesn’t make much difference.

wp_head is just a hook that grabs stuff from another location and adds it to the theme head. No reason why you can’t add that same code to the head itself, either way, it all works the same. There isn’t a right or wrong way, just whatever floats the authors boat.

by
by
by
by
by
by