Hi all,
I've been searching around this forum and around the internets, but i haven't found an answer.
I'm trying to write a shortcode in kfunctions.php for embedding bandcamp.com content. I've manage to create one for vimeo too and it works like a charm, but somehow i cant get a shortcode for bandcamp working.
Here's what i have so far (youtube and vimeo)
The embed-code for bandcamp is
Where ********** is the album ID and * is the track ID.
Any help would be appreciated
I've been searching around this forum and around the internets, but i haven't found an answer.
I'm trying to write a shortcode in kfunctions.php for embedding bandcamp.com content. I've manage to create one for vimeo too and it works like a charm, but somehow i cant get a shortcode for bandcamp working.
Here's what i have so far (youtube and vimeo)
- Code: Select all
<?php
// YouTube Shortcode
// Usage: [youtube video="http://www.youtube.com/watch?v=5PsnxDQvQpw"]
// [youtube http://www.youtube.com/watch?v=1aBSPn2P9bg]
// [youtube 1aBSPn2P9bg]
$FUNCS->register_shortcode( 'youtube', 'youtube_handler' );
function youtube_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'video' => 'http://',
'width' => '418',
'height' => '215',
), $params) );
// Video parameter is link or ID?
if ( (substr($video, 0, 7) == 'http://') || (substr($video, 0, 8) == 'https://') ){
/*
Example links that can be handled:
http://www.youtube.com/watch?v=5PsnxDQvQpw
http://youtube.com/watch?v=5PsnxDQvQpw
http://youtube.com/watch?gl=US&hl=en-US&v=5PsnxDQvQpw
http://youtube.com/v/5PsnxDQvQpw&rel=1
*/
if( !preg_match('#https?://(?:[^\.]+\.)?youtube.com.*(?:\?v=|&v=|/v/)([\w_-]+)#i', $video, $matches) ) return;
$video = $matches[1];
}
// Sanitize parameters
$video = htmlspecialchars( $video, ENT_QUOTES );
$width = (int)$width;
$height = (int)$height;
// Output HTML
$html =<<<EOS
<iframe class="youtube" type="text/html" width="$width" height="$height" src="http://www.youtube.com/embed/$video?rel=0&autohide=1" frameborder="0"></iframe>
EOS;
return $html;
}
// Vimeo Shortcode
// Usage: [vimeo 40613192]
$FUNCS->register_shortcode( 'vimeo', 'vimeo_handler' );
function vimeo_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'id'=>'',
'width' => '418',
'height' => '215',
), $params) );
// Sanitize parameters
$id = htmlspecialchars( $id, ENT_QUOTES );
$width = (int)$width;
$height = (int)$height;
// Output HTML
$html =<<<EOS
<iframe class="youtube" src="http://player.vimeo.com/video/$id?byline=0&portrait=0&color=FFFFFF;badge=0" width="$width" height="$height" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
EOS;
return $html;
}
?>
The embed-code for bandcamp is
- Code: Select all
<iframe style="border: 0; width: 100%; height: 120px;" src="http://bandcamp.com/EmbeddedPlayer/album=**********/size=medium/bgcol=ffffff/linkcol=0687f5/t=*/transparent=true/" seamless></iframe>
Where ********** is the album ID and * is the track ID.
Any help would be appreciated
