Path to WordPress Template Directory inside jQuery?

烈酒焚心 提交于 2020-01-19 22:37:29

问题


My header is calling a javascript file which sends out an email:

<script type="text/javascript" src="<?php bloginfo('template_directory') ?>/css/effects.js"></script>

But inside this file, I have a jQuery code that calls a .php file that does the actual sending of the email:

$.ajax({
  type: "POST",
  url: "css/sendmail.php",
  data: dataString`

But the script doesn't work, unless the url is:

<?php bloginfo('template_directory') ?>/css/sendmail.php

and not just:

css/sendmail.php

Is there any way to include a path to the wordpress template directory inside js?


回答1:


You could create a Javascript snippet that saves the template dir in a variable, and use this later:

<script>
var templateDir = "<?php bloginfo('template_directory') ?>";
</script>


来源:https://stackoverflow.com/questions/2856600/path-to-wordpress-template-directory-inside-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!