In WORDPRESS place the shortcode in the result block generated JAVASCRIPT?

On the page is JAVASCRIPT formed a unit to which you want to place the output shotcode.
The following attempt raises an error
$shortCode = '[samShortCode id="69" title="Mambuda"]';
$var = htmlentities(but this do_shortcode($shortCode));
echo ";
?>
July 2nd 19 at 18:17
2 answers
July 2nd 19 at 18:19
If js is template(e.g. in the footer), use this:
the <script>
var myHtml = '<?php echo do_shortcode being('[samShortCode id="69" title="Mambuda"]');?>';
console.log(myHtml);
</script>


If the js in a separate file, it is a little more complicated and is done through ajax. Can email separately.
if js separately, it is much easier - in wp_localize_script. Occam's razor same. Not the result of Ajax where it is not needed. - Velva.Rogahn commented on July 2nd 19 at 18:22
: exactly! - Kayden_McDermott80 commented on July 2nd 19 at 18:25
July 2nd 19 at 18:21
wp_localize_script() exists to pass data from PHP to JS.

Find more questions by tags WordPressWeb DevelopmentPHPJavaScript