0

How do i echo the following HTML and PHP in jQuery to make it render as html?

<script src="<?php bloginfo('template_directory'); ?>/js/carousel.js"></script>
4
  • What html are you talking about? Commented May 16, 2016 at 10:22
  • save <?php bloginfo('template_directory'); ?> in a variable, like: var dir = '<?php bloginfo('template_directory'); ?>'; then use it in the script src. like: <script src="'+var+'/js/carousel.js"></script> Commented May 16, 2016 at 10:22
  • <script src="<?php bloginfo('template_url'); ?>/js/carousel.js"></script> Commented May 16, 2016 at 10:22
  • Yes, save it in a variable like @FrayneKonok suggested. or use .html inside another <script> tag Commented May 16, 2016 at 10:25

3 Answers 3

1

You can save it inside a variable like

var script = "<?php bloginfo('template_directory'); ?>" + "/js/carousel.js";

Watch out for the quote you use.

Sign up to request clarification or add additional context in comments.

Comments

0

Try the below code.

$('head').append('<script src="<?php bloginfo('template_directory'); ?>/js/carousel.js"></script>')

It will add the code at the end of head tag. Assuming all your jquery library available in head tag

Note: It will work only if you write this code inside a php file

Comments

0

May be this is what u want

<script src="<?php echo bloginfo('template_directory'); ?>/js/carousel.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.