Technically, your problem (as already pointed out) is that you are using a function that echo
s instead of return
s your path. However, the use of bloginfo
/get_bloginfo
to retrieve theme directory paths is long since discouraged.
- 'stylesheet_url' - Displays the primary CSS (usually
style.css) file URL of the active theme. Consider echoing get_stylesheet_uri() instead.
- 'stylesheet_directory' - Displays the stylesheet
directory URL of the active theme. (Was a local path in earlier
WordPress versions.) Consider echoing
get_stylesheet_directory_uri() instead.
-
'template_url' / 'template_directory' - URL of the
active theme's directory ('template_directory' was a local path before
2.6; see get_theme_root() and get_template() for hackish alternatives.) Within child
themes, both get_bloginfo('template_url') and get_template() will
return the parent theme directory. Consider echoing
get_template_directory_uri() instead (for the parent template
directory) or
get_stylesheet_directory_uri() (for the child template directory).
http://codex.wordpress.org/Function_Reference/bloginfo
As per the Codex section just quoted, the equivalent, correct code should use get_template_directory_uri()
:
function enqueue_scripts() {
if ( ! is_admin() ) {
$scriptsrc = get_template_directory_uri() . '/scripts.js';
wp_register_script( 'scripts', $scriptsrc );
wp_enqueue_script( 'scripts' );
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
Note that get_template_directory_uri()
will always return a path to the parent theme. If you wish for a child theme to be able to override this file, need get_stylesheet_directory_uri()
Additionally, please do not use a function name as generic as enqueue_scripts
. That is likely to cause trouble and is bad practice.
scripts
seems a little generic for handle, might something else be colliding with it?