WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using video shortcode in custom field (4 posts)

  1. lizzmo
    Member
    Posted 2 years ago #

    I've looked through the forums and the general consensus seems to be that this code should work:

    <?php if (get_post_meta($post->ID, 'VIDEO', true)) {
    echo do_shortcode(get_post_meta($post->ID, 'VIDEO', true));
    } else { }; ?>

    But all that shows up is the shortcode as plain text. Help please!

    Heres a link to the page: http://design-science.org.uk/the-sum-of-all-paths/

    The video should have been above the slideshow.

  2. ysr5
    Member
    Posted 2 years ago #

    what about this

    you replace the output to just have the video id.

    // delete youtube from output
    str_replace("youtube","",$yourOutputShownOnYourSide);
    
    // you will get something like "[ yu44JRTIxSQ]"
    str_replace("[","",$yourOutputShownOnYourSide);
    
    // you will get something like " yu44JRTIxSQ]"
    str_replace("]","",$yourOutputShownOnYourSide);
    
    // you will get something like " yu44JRTIxSQ"
    trim($yourOutputShownOnYourSide);
    
    // you will get something like "yu44JRTIxSQ"

    than you can create a link to that video or embed the vid
    for link:

    // echo link
    echo "http://www.youtube.com/watch?v=".$yourOutputShownOnYourSide;
    
    // echo embed
    echo "<iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/".$yourOutputShownOnYourSide."\" frameborder=\"0\">
    </iframe>";

    (not tested the code)

  3. lizzmo
    Member
    Posted 2 years ago #

    Thanks very much, I simplified it a bit, but you definitely put me in the right direction!

    Changed to vimeo because the youtube video wouldn't follow its z-index, even when I added wmode.

    Heres what I used in the end:

    <?php if (get_post_meta($post->ID, 'VIDEO', true)) {
    echo "<iframe src=\"http://player.vimeo.com/video/".$video."?byline=0&portrait=0&color=0096db\" width=\"466\" height=\"262\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
    } else { }; ?>

    So all I have to put in the custom field is the video id number, no need for a shortcode or str_replace.
    Thanks again!

  4. ysr5
    Member
    Posted 2 years ago #

    that looks fine :-) good job

Topic Closed

This topic has been closed to new replies.

About this Topic