Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created May 27, 2015 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codearachnid/a3b3bd689e4c091a4fb9 to your computer and use it in GitHub Desktop.
Save codearachnid/a3b3bd689e4c091a4fb9 to your computer and use it in GitHub Desktop.
A simple modification to implement filters for embed display within archive and ajax shortcodes for Series Engine.
<?php
/**
* implement a filter hook by replacing the original echo in
* serieslistings.php lines 621, 727
* ajaxlink.php lines 632, 746
*/
echo stripslashes($enmse_singlemessage->embed_code);
// with the new filter
echo apply_filters('enmse_embed_display', stripslashes($enmse_singlemessage->embed_code) );
// in functions override the filter with the following code
add_filter( 'enmse_embed_display', 'custom_enmse_embed_display' );
function custom_enmse_embed_display( $embed_code = '' ){
if(filter_var($embed_code, FILTER_VALIDATE_URL)){
$embed_code = wp_oembed_get($embed_code);
}
return $embed_code;
}
/**
* if a custom YouTube (or other video) player is desired a custom override for the
* player can easily be implemented with exending the `wp_oembed_get` method by
* extending hook `oembed_result`
*/
add_filter('oembed_result', 'custom_oembed_youtube_no_title_example', 10, 3);
function custom_oembed_youtube_no_title_example( $html, $url, $args ) {
// Only run this for YouTube embeds
if ( !strstr($url, 'youtube.com') )
return $html;
// Get embed URL
$url_string = parse_url($url, PHP_URL_QUERY);
parse_str($url_string, $id);
// Set default arguments
$defaults = array(
'modestbranding' => true,
'controls' => true,
'width' => '560',
'height' => '315',
'showinfo' => true,
'rel' => true
);
// Merge args with defaults
$args = wp_parse_args( $args, $defaults );
// Define variables
extract( $args, EXTR_SKIP );
// Add custom parameter values to IFRAME
if ( isset($id['v']) ) {
return '<iframe width="' . intval($width) . '" height="' . intval($height) . '" src="http://www.youtube.com/embed/' . $id['v'] . '?modestbranding=' . intval( $modestbranding ) . '&controls=' . intval( $controls ) . '&rel=' . intval($rel) . '&showinfo=' . intval($showinfo) . '" frameborder="0" allowfullscreen></iframe>';
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment