get posts – WordPress block editor embeds not working in theme (single.php)

Question

I am trying to embed ‘spotify‘ and ‘youtube‘ services in the block editor. When added from the admin, they are displayed fine in the block editor, but when the post content is printed from the theme (single.php), only the respective urls are printed. The rendered HTML looks like:

For Spotify:

<figure class="wp-block-embed is-type-rich is-provider-spotify wp-block-embed-spotify wp-embed-aspect-21-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://open.spotify.com/episode/xxxxxx&dl_branch=1
</div></figure>

For Youtube:

<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://www.youtube.com/watch?v=xxxxxx
</div></figure>

In single.php, I’m obtaining the post content through get_posts() and printing the content with:

<?php echo do_shortcode($tpostObj->content); ?>

The other contents like texts, images etc are working fine. If the embeds are done with custom HTML iframe, they are working.

Thanks in advance.

0
sariDon 1 month 2021-06-29T18:07:54-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse