Wordpress - Can't enqueue scripts in the footer?
Where did you put your code ?
- the "true" arguments goes in the
wp_register_script();
, not thewp_enqueue_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);
?>
- 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');
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
);
I had the same problem and after doing some search I was missing this function in my custom theme:
<?php wp_footer();?>