, , , , , .
, , , . , , , , , .
YouTube, https://www.youtube.com/watch?v=eh7lp9umG2I, " ( ).
. , , "the_content".
, , , - DRY.
, .
function your_shortcode_handler($atts)
{
$url = $atts['video'];
if (isset($url))
{
$type = 'application/x-shockwave-flash';
$url = str_replace("watch?v=", 'v/', $url);
$obj = "<object data='$url' type='$type'><param name='src' value='$url' /></object>"
return $obj;
}
}
add_shortcode('your_shortcode_name', 'your_shortcode_handler');
function your_shortcode_filter($content)
{
$pattern = "/\[your_shortcode_name(.*?)\]/";
$content = preg_replace($pattern, '', $content);
return $content;
}
add_filter('the_content', 'your_shortcode_filter');
function stealFromContent($content)
{
$pattern = "/\[your_shortcode_name(.*?)\]/";
$match = null;
preg_match($pattern, $content, $match);
if (is_array($match) and $match[0] != '')
{
return $match[0];
}
return '';
}
$youtube_video = stealFromContent();
echo $youtube_video;
. , , . regexing the_content, , , javascript.
do_shortcode , . , , , - .
source file for reference.
source
share