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:
<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>
<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.