Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

5 Answers 5

up vote 3 down vote accepted

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()

share|improve this answer
    
so the tutorial semi helped...it helped me understand a bit more and I actually ended up using the custom tutorial to preserve html tags but for some reason no matter what i put in my functions.php file it doesn't seem to make any changes to my blog page...before this I tried the remove_filter on the twenty_eleven functions as that is my parent theme... –  Marques Feb 28 '12 at 15:38
    
I read the codex for the functions.php file and it should auto work without having to do anything else and the tutorial I followed has you overwrite the wp variables for excerpt_length etc.. so this should work? –  Marques Feb 28 '12 at 17:00
    
You're going to need to be significantly more specific if you want any constructive help. What parts are and aren't working? –  m0r7if3r Feb 28 '12 at 21:56
    
nothing is working lol, i used the "good tutorial" link you posted and put the settings into the functions.php file from the "Preserve HTML Tags in the Excerpt and Other Settings" article. I changed the count in the following to 500 to see if the excerpt length would change and it didnt... $excerpt_word_count = 55; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/ $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); so: i currently changed the_content() to the_excerpt() and did what i just said above and my parent theme is twenty eleven –  Marques Mar 1 '12 at 5:42
    
And what troubleshooting steps did you take? Where specifically is it failing? –  m0r7if3r Mar 1 '12 at 10:26

@Marques: 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.

share|improve this answer
    
I have excerpt_length, continue_reading, auto_excerpt_more, and custom_excerpt_more all commented out in the functions.php of twentyeleven. No matter what i change in my functions.php file nothing happens. i have tried adding the html tags to allow, changing the excerpt length, and the excerpt ending. Unfortunately this is locally installed right now which i know is no help. Im just not sure what else could be keeping this from working! –  Marques Mar 3 '12 at 1:58
    
So i just now went into the formatting.php file and tried to change the excerpt length directly and still nothing changed! I mentioned that I have a static front page and have this as a separate blog page should that change anything!? –  Marques Mar 3 '12 at 2:01
    
Also if I uncomment the twentyeleven functions and change there values i do see changes in the excerpt length but I would like to do this correctly instead of hacking it together! –  Marques Mar 3 '12 at 2:08

Create a custom meta box, and call it below your excerpt may be another option: http://wp.tutsplus.com/tutorials/plugins/how-to-create-custom-wordpress-writemeta-boxes/

share|improve this answer

@Marques: 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. Boutros.

share|improve this answer
    
THank you glad its not just me! I guess i will hack it for now lol –  Marques Mar 5 '12 at 20:58
    
Boutros AbiChedid I was just curious if you had any updates on this issue? –  Marques Mar 13 '12 at 13:56

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. http://codex.wordpress.org/Post_Formats

share|improve this answer
    
Post formats are not custom; they are a fixed set and can not be extended with custom values. –  toscho Apr 2 '13 at 9:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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