Skip to content

Instantly share code, notes, and snippets.

@Pushplaybang
Last active December 11, 2015 09:08
Show Gist options
  • Save Pushplaybang/4578072 to your computer and use it in GitHub Desktop.
Save Pushplaybang/4578072 to your computer and use it in GitHub Desktop.
starting point for dealing with embeds from the _format_video_embed meta feild
<?php
// Display Videos
// Utility function - allow us to strpos an array
if ( ! function_exists( 'video_strpos_arr' )) {
function video_strpos_arr($haystack, $needle) {
if( !is_array($needle) ) $needle = array($needle);
foreach( $needle as $what ) {
if( ($pos = strpos($haystack, $what) ) !==false ) return $pos;
}
return false;
}
}
// Get Ready Display the Video
$embedCheck = array("<embed", "<video", "<ifram");// only checking against the first 6
$mykey_values = get_post_custom_values('_format_video_embed');
$media_to_display = '';
// iterate over values passed
foreach ( $mykey_values as $key => $value ) {
if ( !empty($value) ) {
$firstCar = substr($value, 0, 6); // get the first 6 char.
// if its a http(s).
if ( strpos($firstCar, "http:/" ) !== false || strpos($firstCar, "https:" ) !== false ) {
// send it to wp_oembed to see if the link is oembed enabled.
(wp_oembed_get($value) !==false ?
$media_to_display = '<div class="video" style="width:100%; overflow:hidden;">' .
wp_oembed_get($value) . '</div>' :
// if not output a link.
$media_to_display = '<a class="button videolink" href="' .
$value . '" target="_blank">Video link: ' . the_title() . '</a>'
);
}
// if its the embed code that matches our array defined above.
else if ( video_strpos_arr($firstCar, $embedCheck ) !== false ) {
$media_to_display = '<div class="video" style="width:100%; overflow:hidden;">' .$value. '</div>';
}
}
}; // end foreach
if ( is_singular() ) {
// output a filtered excerpt displaying the result of the conditionals above.
echo apply_filters('the_content', $media_to_display );
the_content();
} else {
// output a filtered excerpt displaying the result of the conditionals above.
get_template_part( 'loop/loop', 'indextitle' );
echo apply_filters('the_excerpt', $media_to_display );
?><p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="button">Read More</a> <?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment