Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...