call function called by [embed] shortcode direct (8 posts)

  1. davidswain
    Posted 5 years ago #


    I am trying to call the function called by the [embed] shortcode directly.

    I am storing a video url in a custom field and therefore cannot use the shortcode 'as is but i cannot find where the shortcode is defined.

    My reasoning is even though the shortcode wont work, the function (if calle in a template) will.

    Can anyone help?


  2. MichaelH
    Posted 5 years ago #

    To use a shortcode in a template

    <?php echo do_shortcode('[catlist id=1 numberposts=5)]'); ?>
  3. davidswain
    Posted 5 years ago #

    Doesnt work im afriad!

    I tried it with the following code:

    <?php echo do_shortcode('[­embed]http://www.youtube.com/watch?v=CSA657kxJQw[/embed]'); ?>

    and it just echoed the content

    remove the echo

    <?php do_shortcode('[­embed]http://www.youtube.com/watch?v=CSA657kxJQw[/embed]'); ?>

    rendered nothing

  4. MichaelH
    Posted 5 years ago #

    Sorry, don't know how to do that. Might look around in wp-includes/media.php to see how it handles embed shortcode stuff.

  5. davidswain
    Posted 5 years ago #

    Thanks Michael

    Had a look through media.php but i dont really understand it!

  6. davidswain
    Posted 5 years ago #

    Should anyione be interested the solution is:

    if (!empty($full)) {
           $var = apply_filters('the_content', "[embed]" . $full . "[/embed]");
    		echo $var;

    where $full is the value of the url to be embed (eg http://www.youtube.com/watch?v=wLh6F7G7rPA) from a custom field

  7. luckykind
    Posted 5 years ago #


    I used your solution, however I was running into problems with other filters applied to 'the_content'... so after much searching... I finally came upon a better solution to this (see below) and wanted to save others the aggravation... :)

    global $wp_embed;
    $post_embed = $wp_embed->run_shortcode('[embed]your-video-url[/embed]');

    Mod Edit: Modified the code to global $wp_embed instead of creating a new instance of the WP_Embed class which is the incorrect way to do it.

  8. archon810
    Posted 4 years ago #

    @luckykind, brilliant, I was looking to see why do_shortcode with embed wasn't working - it was driving me nuts. Your solution works great, though it's so silly that we need to do this so manually.

Topic Closed

This topic has been closed to new replies.

About this Topic