I’d like to know how to use the get_bloginfo( 'template_directory' )
tag in an external JS file.
I just found out that it’s possible using the wp_localize_script
function but I didn’t manage to get it to work …
functions.php
wp_enqueue_script( 'custom_js' );
wp_localize_script('custom_js', 'wp_urls', array( 'template_dir' => get_bloginfo( 'template_directory' ) ));
header.php
(beneath wp_head();
)
<script>
alert(wp_urls.template_dir);
</script>
'wp_urls'
might work?<head>
before thealert
?wp-head();
is called before thealert
but there’s nothing added in the header bywp-head();
.