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? – akTed Jan 21 at 14:46<head>before thealert? – s_ha_dum Jan 21 at 15:18wp-head();is called before thealertbut there’s nothing added in the header bywp-head();. – user1706680 Jan 21 at 16:06