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


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">

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">

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.

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

Leave an answer