Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The WordPress codex says:

$in_footer

(boolean) (optional) Normally scripts are placed in the section. If this parameter is true the script is placed at the bottom of the . This requires the theme to have the wp_footer() hook in the appropriate place. Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer. (New in WordPress 2.8) Default: false

So I added true after each script's src path:

/**
     * JavaScript
     */

    function my_scripts_method() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js', true );
        wp_enqueue_script( 'jquery' );
    }

    add_action('wp_enqueue_scripts', 'my_scripts_method');

    function media_queries_script() {
        wp_register_script( 'mediaqueries', get_template_directory_uri() . '/js/css3-mediaqueries.js', true );
        wp_enqueue_script( 'mediaqueries' );
    }

    add_action('wp_enqueue_scripts', 'media_queries_script');

    function custom_script() {
        wp_register_script( 'custom', get_template_directory_uri() . '/js/custom.js', true );
        wp_enqueue_script( 'custom' );
    }

    add_action('wp_enqueue_scripts', 'custom_script');

    function replace_script() {
        wp_register_script( 'replace', get_template_directory_uri() . '/js/jquery.ba-replacetext.min.js', true );
        wp_enqueue_script( 'replace' );
    }

    add_action('wp_enqueue_scripts', 'replace_script');

But the scripts are still being included in the header.

Any suggestions to fix that?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Where did you put your code ?

  1. the "true" arguments goes in the

wp_enqueue_script( '' );

, not the wp_register_script() ;

the functions is :

<?php wp_enqueue_script('handle', 'src', 'deps', 'ver', 'in_footer'); ?>

meaning

    <?php wp_enqueue_script('NameMySccript', 'path/to/MyScript', 
'dependencies_MyScript', 'VersionMyScript', 'InfooterTrueorFalse'); ?>

E.G.

<?php wp_enqueue_script('my_script', WP_CONTENT_URL . 'plugins/my_plugin/my_script.js', array('jquery', 'another_script'), '1.0.0', true); ?>

  1. does your theme have <?php wp_footer(); ?> at the end of the page ?

3.add the action with add_action('wp_print_scripts', 'your function');

That being said , your best practice would be :

<?php  
if (function_exists('load_my_scripts')) {  
    function load_my_scripts() {  
        if (!is_admin()) {  
        wp_deregister_script( 'jquery' );  
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');  
        wp_enqueue_script('jquery');  
        wp_register_script('myscript', bloginfo('template_url').'/js/myScript.js'__FILE__), array('jquery'), '1.0', true );  
        wp_enqueue_script('myscript');  
        }  
    }  
}  
add_action('init', 'load_my_scripts');  
?>  

or add_action('wp_print_scripts', 'dl_register_js');

share|improve this answer
    
Thanks it is working now but I realized that placing the true in either wp_enqueue or wp-register_script work just fine. –  janoChen Jan 5 '12 at 15:43
    
@krembo99 The wp_register_script() takes the same amount of arguments and both add to the $wp_scripts global array and the data subarray. Combined the wrong information with the awfull readability of your answer, I've to give you a -1 (will be removed on rework). –  kaiser Jan 5 '13 at 17:07
add comment

You are passing a bool value to the dependency param. Try this:

 wp_enqueue_script(
      'replace', 
       get_template_directory_uri().'/js/jquery.ba-replacetext.min.js',
       array('jquery'), 
       '', 
       true
);
share|improve this answer
add comment

For me when I have these issues, I check the output code WP generates and move it. Plugins are a headache. I simply moved the js links created, copied them to the footer and all works. Probably not a WP recommendation, but it works.

share|improve this answer
2  
Plugins are a headache - Huh? –  Brian Fegter Oct 7 '12 at 1:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.