0

So I have a theme in development. When I go to make a post, the post formats don't seem to change anything. I'm not sure if they're supposed to change the page or not...

But what I want is for when I do a video post (either an uploaded video or a link), for the video to show up on the Posts page (which displays all posts).

I've tried adding a couple of things to functions.php, but to no avail... Can anyone help please? Images show up, just not videos

0

For a post format, you can refer to this link https://codex.wordpress.org/Post_Formats

To show videos on posts page,just modify the excerpt filter and display the excerpt.

Add following code in functions.php

function custom_wp_trim_excerpt($text) {
    $raw_excerpt = $text;
    if ( '' == $text ) {
        $text = get_the_content(''); // Original Content
        $text = strip_shortcodes($text); // Minus Shortcodes
        $text = apply_filters('the_content', $text); // Filters
        $text = str_replace(']]>', ']]>', $text); // Replace
        $excerpt_length = apply_filters('excerpt_length', 50); // Length
        $excerpt_more = apply_filters('excerpt_more', ' ' . '<a class="readmore" href="'. get_permalink() .'">&raquo;</a>');
        $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
        // Use First Video as Excerpt
        $postcustom = get_post_custom_keys();
        global $post; 
        $postid = $post->ID;
        if ($postcustom){
            $i = 1;
            foreach ($postcustom as $key){
            if (strpos($key,'oembed')){
                foreach (get_post_custom_values($key) as $video){
                    if ($i == 1){
                        $text = $video."<br/>".$text;
                    }
                    $i++;
                }
            }
        }
    }
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_wp_trim_excerpt');

Put the excerpt tag where you want to display the video.

echo get_the_excerpt();

Add video URL in post content (visual editor) and it will display video in excerpt also.

like : https://vimeo.com/VIMEO_ID

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.