amp-youtube component check if exist?
-
Hi, please tell me how can I check if the YouTube component is already included?
I have posts in which we insert iframe YouTube through the meta field (<iframe width="500" height="281" src="https://www.youtube.com/embed/ws0npD8T4mU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
) and if the meta field is filled, then instead of the featured image of the post I display YouTube. The problem is that if there is no YouTube in the body of the news, but it is only in the meta field, then in the amp code of the amp-YouTube page, the component is not connected and the video is not visible on the page, if the body of the news is added to YouTube then it doesn’t work. I thought just to connect to all pages of the component YouTube like thisadd_action( 'amp_post_template_head', function() { ?> <script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script> <?php } );
but in this case, we will have a YouTube component connected 2 times, it is probably not very normal…
My featured-image.php
https://pastebin.com/RNBV5dsrmaybe you can tell me how to solve the issue so that it is correct? Thanks
Live example:
Case 1: https://kr.informator.ua/2018/12/03/v-krivom-roge-zaderzhali-grabitelya-v-maske-tigra-i-s-toporom/amp/YouTube video is added through the meta field and it is in the code page, the video does not display on the page (there is no video in the content of the post)
YouTube video added through the meta field and in the news content, everything works fine.
- The topic ‘amp-youtube component check if exist?’ is closed to new replies.