Show Video in Excerpt

So I recently figured out how to change my blog page to display excerpts by changing the <?php the_content(); ?> to <?php the_excerpt(); ?> in my index.php file.

I am using a custom child theme and unfortunately had to edit the parent twenty eleven functions.php file to modify the continue reading link to read more, which I know isn’t the correct way, but for some reason when I created a function in my functions.php in the theme folder it wasn’t overriding and when I deleted the lines in the parent functions.php file the post content disappeared!? (I guess that is question 1)

My real question now is when I do get the excerpts to work video does not display in the excerpt post so it looks like I have a sentence and the post ends when there should be a video displayed. I don’t want users to be confused and think that is the end of the post…

  1. Is there another way to override the functions.php file so that I can do the excerpts read more without editing the parent functions.php

  2. How can I get my videos to display in my excerpts?

Thanks and I hope this makes sense let me know if you need clarification!

Solutions Collecting From Web of "Show Video in Excerpt"

filtering the_excerpt()

If you remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ) and add your own get_the_excerpt filter you can do this.

The default filter (wp_trim_excerpt()) can be found on line 2023 of /wp-includes/formatting.php if you want to just modify that. The extent of what you need to do is just modifying which tags are allowed in strip_tags().

overriding functions.php

As for overriding the functions.php, the codex is pretty clear on what you need to do.

update: Here’s a good tutorial on allowing tags in the_excerpt()

I wrote the tutorial you are referring to:
How To preserve HTML Tags in WordPress Excerpt Without a Plugin

The “MAIN_CODE” you are adding is conflicting with the following functions in “functions.php” file for twentyeleven theme: specifically “twentyeleven_excerpt_length()” starting line 312 of the code. You need to remove (or comment out) this filter.

There could be other functions in the “functions.php” file of twentyeleven like (not 100% sure since I haven’t tested it):
“twentyeleven_custom_excerpt_more()”, “twentyeleven_auto_excerpt_more()”

About allowing videos in the excerpt, when I wrote the code I haven’t test for this.
Are you using the HTML5 <video> tag?
If you can share a post with a video, I can take a look and see if it works…

Hope this helps.

Boutros AbiChedid.

I just tested the The “MAIN_CODE” from the tutorial above on my Blog for TwentyEleven and TwentyTen themes. link below:

How To preserve HTML Tags in WordPress Excerpt Without a Plugin

You are right, and I just want to confirm your observation, that nothing changes in the MAIN PAGE OF THE BLOG even with commenting out functions in the “functions.php” file.
So definitely, there is a theme conflict with my code and not local install issue. I am surprised that my code did not work for these 2 themes for the main page.

However, for the archive pages the “MAIN_CODE” works as intended for Twentyten but not TwentyEleven?? (you still have to comment out 2 functions ‘twentyten_auto_excerpt_more()’ and ‘twentyten_excerpt_length()’ in “functions.php” file )

I will investigate my code specifically for these 2 themes, and if/when I find the solution, I will get back.

Best solution to this problem is using built-in function called CPF, Custom Post Formats.

Add theme support for VIDEO format. Then in theme loop add conditional statement that if is Post Format == to Video, then use the_content instead of the_excerpt.

This will solve the issue and will show the video even on category pages or homepage where other posts excerpts are being shown.

Here is link for CPF from codex. With just one line of code you can add support to your theme for video format.