0

Is there any way to do something like this this

I use the blow code but it does not work on my theme(jannah)

/*-----------------------------------------------------------------------------------*/
# Helper Functions
/*-----------------------------------------------------------------------------------*/
function get_all_string_between( $string, $start, $end ) {
    $result = [];
    $string = " " . $string;
    $offset = 0;
    while ( TRUE ) {
        $ini = strpos($string, $start, $offset);
        if ( $ini == 0 ) {
            break;
        }
        $ini      += strlen($start);
        $len      = strpos($string, $end, $ini) - $ini;
        $result[] = substr($string, $ini, $len);
        $offset   = $ini + $len;
    }

    return $result;
}


/*-----------------------------------------------------------------------------------*/
# Video Preview
/*-----------------------------------------------------------------------------------*/
function thf_the_post_video_preview() {
    global $post;
    $html   = '';
    $videos = get_all_string_between($post->post_content, '[embed]', '[/embed]');
    if ( !empty($videos[0]) ) {
        $src  = $videos[0];
        $mime = wp_check_filetype($src);
        $mime = $mime['type'];

        $html = '<video class="thf-video-preview" id="video-' . $post->ID . '" poster="' . get_the_post_thumbnail_url($post->ID, 'large') . '" preload="none">';
        $html .= '  <source type="' . $mime . '"src="' . $src . '"/>';
        $html .= '  Your browser does not support the video tag.';
        $html .= '</video>';
    }

    echo $html;
}

and use it on them like this

<div class="video-preview">
    <?php   thf_the_post_video_preview();?>
 </div>
  • @fuxia I add some new information – D.JCode Feb 6 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.