1

I'm not sure if i can ask this way, but i will try.
I use this YouTube fullscreen jquery plugin - Link
The problem is that i have to enter the YouTube video ID manually in the script. How do i get my ACF value to replace the videoId?

I have tried like this

<script>

  var jsVideo = <?php echo get_field('hero_baggrundsvideo'); ?>;

(function($) {
  $('#heroVideo').YTPlayer({
    fitToBackground: true,
    videoId: ''.$jsVideo.''
  });
})(jQuery);
</script>

But it does not work. I have placed this script inside my php file.
I hope you get what i am trying to say.

Please correct me, if my question is wrong.

Keviin Cosmos
  • 177
  • 14
  • I just found out that i can't run the script in my php file - then the plugin won't execute.. But if you know how to use the variable, i'll be happy to know :) – Keviin Cosmos Feb 10 '19 at 14:31

1 Answers1

2

Above everything else, your JS code has syntax problems.

Dot . concatenates strings in PHP, Js uses +. You are not adding quotes around the video id. Try this and check the developer console for other errors.

<script>

  var jsVideo = "<?php echo get_field('hero_baggrundsvideo'); ?>";
  console.log("I am playing: "+jsVideo);

(function($) {
    $('#heroVideo').YTPlayer({
    fitToBackground: true,
    videoId: jsVideo;
 });
})(jQuery);
</script>
Eriks Klotins
  • 4,042
  • 1
  • 12
  • 26