WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Insert Youtube ID from Custom Field into Embed Code

[Resolved] Insert Youtube ID from Custom Field into Embed Code

  • I have a custom field setup called “youtubeid”. One can insert the ID of a youtube video into it, then on my single.php page, it checks to see if that ID exists, then it inserts that ID into some embed code to put the youtube video into the post. This works nicely for me because i can then also pull the thumbnail image of the video from youtube for my archives page. The video part works in every browser EXCEPT Internet explorer. Thumbnails work fine.

    I’m wondering if IE just doesn’t like you putting php into video embedding code?

    This is what my code looks like to display the video.

    <?php $youtubeid = get_post_meta($post->ID, "youtubeid", true); ?>
    			<?php if($youtubeid !== '') { ?>
    				<div class="video_style">
    				<object type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/<?php 
    
    echo $youtubeid; ?>">
    					<param name="movie" value="http://www.youtube.com/v/<?php echo "youtubeid"; ?>" />
    				</object>
    				</div>
    			<?php } ?>

    Any thoughts on why IE won’t display the video?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Oh I should also add, upon viewing the source in Internet explorer, it just shows this

    <div class="video_style">
    				<object type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/1UcfjMNMYWo">
    					<param name="movie" value="http://www.youtube.com/v/youtubeid" />
    				</object>
    				</div>

    For the param value it shows http://www.youtube.com/v/youtubeid I wonder if something is wrong with my php then?

    Yes, there was an error- here’s the fixed code:

    <?php $youtubeid = get_post_meta($post->ID, "youtubeid", true); ?>
    			<?php if($youtubeid !== '') { ?>
    				<div class="video_style">
    				<object type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/<?php echo $youtubeid; ?>">
    					<param name="movie" value="http://www.youtube.com/v/<?php echo $youtubeid; ?>" />
    				</object>
    				</div>
    			<?php } ?>

    Looking to do something similar to the code for post videos, but display a number of youtube videos in the sidebar from video IDs stored in custom field(s) in Pages. Allowing different videos to be shown for different pages.

    If there is an existing plugin that can do this thats great or a similar code loop that can be put in the sidebar.

    Hi thanks for this useful information

    However, I don’t know where to insert the code within the single page.php file?

    Can anybody help?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Insert Youtube ID from Custom Field into Embed Code’ is closed to new replies.