Do_Shortcode not working for Embed

I’m trying to use Custom Field types to embed Youtube videos in a more organized fashion and using the Do_Shortcode() would seem to work perfectly, however this:

<?php echo do_shortcode(''); ?>

Does not seem to work, however in the same single.php file this does work perfectly:

<?php echo do_shortcode(''); ?>

I put them one after another to test them out, any ideas why the shortcode doesn't get parsed (it just shows nothing)</p>

<p>If I do the embed shortcode directly into the post it works perfectly.</p>

<p>Thanks,</p>

<p>Jordan</p>
</div><br><h2 class="mb0" data-answercount="3">
3 s
<span style="display:none;" itemprop="answerCount">3</span>
</h2><br><div class="s-prose js-post-body" itemprop="text">
<p>Simply put <code></code> is not a regular shortcode. Most of the time it does nothing. What happens when post content goes through <code>the_content</code> filter is following:</p>

<ol>
<li><p><code>[emded]</code> is currently registered to do nothing ( <code>__return_false()</code> )</p></li>
<li><p><code>WP_Embed->run_shortcode()</code> filter runs with low <code>8</code> priority</p></li>
<li>all shortcodes are disabled</li>
<li><code></code> is registered to <code>WP_Embed->shortocde()</code></li>
<li><code>do_shortcode()</code> executes on content (only doing embeds, since rest is disabled)</li>
<li>shortcodes are restored to original state, <code></code> is back to being useless.</li>
</ol>

<p>So my quick guess for something to try would be:</p>

<pre><code>global $wp_embed;

echo $wp_embed->run_shortcode('whatever‘);

But note that there is also caching involved (embedding results are saved to custom field of the post, otherwise it would need to make HTTP request every time) and you are likely breaking that, unless you are doing it inside loop and close to where it normally works. Maybe even then.

Leave a Comment