在有人说这应该在Wordpress Stackexchange上之前,请仔细阅读,因为这是一个JS查询而不是Wordpress查询。我试图在JS文件中找到Wordpress主题的路径,所以我不必包含完整路径,通常在模板文件中使用<?php bloginfo('template_url'); ?>
但显然我们在JS中工作在这里提交。
我找到了一个论坛帖子,说要在调用JS文件之前使用以下内容:
<script type="text/javascript"><!--
var template_url = "<?php bloginfo('template_url'); ?>";
// -->
</script>
然后在JS文件中放置template_url
但这只是放置&#39; template_url&#39;在路径的中间。
要进入的界线是:
$(this).prev().css({ backgroundImage : 'url(template_url/images/icons/menu-divider.png)' });
我怎样才能获得在这行JS中调用的完整路径?
非常感谢 阿德里安
答案 0 :(得分:-1)
使用此功能可返回您要查找的内容
get_template_directory_uri()
所以,这样做
<script type="text/javascript"><!--
var template_url = "<?php echo get_template_directory_uri(); ?>";
// -->
</script>