Youtube link in post.content doesn't render in a MB view
- This topic has 5 replies, 3 voices, and was last updated 3 years, 6 months ago by
Matt V.
-
AuthorPosts
-
April 16, 2021 at 4:15 AM #27298
Henri
ParticipantHi Metabox,
I have a youtube embeded in the post.content. When I don't use a MB view to display the page, it shows the text and the video. However, when I use a MB view and post the content using the following field:
{{ post.content }}
it does show the text but doesn't render the video, it only shows the url of the video. Is this a bug? How can I resolve this?Kind regards, Henri
April 16, 2021 at 11:31 AM #27306Long Nguyen
ModeratorHi,
It's the normal behavior because the data is saved in the database is the raw value like this
<!-- wp:embed {"url":"https://www.youtube.com/watch?v=cClgQ9kGfAQ","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} --> <figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper"> <code>https://www.youtube.com/watch?v=cClgQ9kGfAQ</code> </div></figure> <!-- /wp:embed -->
then Block editor support showing the video on the frontend, but the MB Views only support to show the raw value. You can change to the embed code
<iframe>
to show the Youtube video via MB Views.April 16, 2021 at 3:13 PM #27315Henri
ParticipantHi Long,
Thanks for you answer. I don't know how I can achieve that. The video is used in the Gutenberg editor as part of the content. So I have text, some images and then the video and then some text again. So when I echo post.content this content all gets displayed, except for the video. If I wrap the post.content in iframe tags only an empty box gets displayed. So how can I target only the video url in existing content with the MB view to wrap that in an iframe tag?
April 16, 2021 at 8:58 PM #27321Long Nguyen
ModeratorYou can use the block Custom HTML and insert the embedded code of Youtube when editing the content. Screenshot https://share.getcloudapp.com/4gu2nAXY
April 19, 2021 at 9:25 PM #27387Henri
ParticipantUsing the HTML block makes sense. It does require me to go into each existing post though to change the Youtube link. This is not ideal, but if there is no workaround then I'll have to see how I'm going to fix this.
October 20, 2021 at 4:56 AM #31403Matt V
ParticipantHi there,
I've been troubleshooting YouTube embeds for much of the afternoon, and I finally narrowed it down to MB Views and found this post.
I don't know exactly how WP handles these embeds on the frontend, but is there a way to load or replicate the necessary script through Views, either as an HTML script tag or in the JS panel?
I know my content editors are going to be using this embed functionality regularly, so I would love to find a way to give them a simple embed block rather than using an HTML block.
Should I expect that this issue will be true with the rest of the embed blocks?
-
AuthorPosts
- You must be logged in to reply to this topic.