Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wpdevhq_get_video(){
- global $wpdevhq_videos;
- $post_id = get_the_ID();
- if( empty( $wpdevhq_videos ) ) $wpdevhq_videos = array();
- if( isset($wpdevhq_videos[$post_id]) ) return $wpdevhq_videos[$post_id];
- $content = get_the_content();
- $content = apply_filters( 'the_content', $content );
- $content = str_replace( ']]>', ']]>', $content );
- $content = trim($content);
- // Is the first line a video?
- list($line, $content) = explode("\n", $content, 2);
- if ( preg_match('/\<\s*(iframe|object|embed)/i', $line) ) {
- $wpdevhq_videos[$post_id] = strip_tags($line, '<iframe><object><embed>');
- }
- else {
- $wpdevhq_videos[$post_id] = false;
- }
- return $wpdevhq_videos[$post_id];
- }
- /**
- * Removes the video from the page
- *
- * @param $content
- *
- * @return mixed
- */
- function wpdevhq_filter_video($content){
- list($line, $rest) = explode("\n", $content, 2);
- if ( preg_match('/\<\s*(iframe|object|embed)/i', $line) ) return $rest;
- else return $content;
- }
- /**
- * You can then return the extracted video via
- */
- echo wpdevhq_get_video()
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement