WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Insert Youtube ID from Custom Field into Embed Code (5 posts)

  1. Hebbylaya
    Member
    Posted 4 years ago #

    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?

  2. Hebbylaya
    Member
    Posted 4 years ago #

    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?

  3. gavingear
    Member
    Posted 4 years ago #

    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 } ?>
  4. sgcweb
    Member
    Posted 4 years ago #

    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.

  5. cashalerts
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic