50 responses to “Replacing WordPress content with an excerpt without editing theme files”

  1. Dan Philibin

    This is awesome; I’ve been looking for a solution to this for a long time. However, I really wish the_excerpt() had a link to the full article at the end. Since the ‘…’ can be customized here as well, why not add a link?

  2. Pangeran

    So, that’s how filter works…

    Then, it means we can just modifying a theme with functions.php…
    Thanks for sharing this…

    But if we change the_content with this, how about plug in that add_action to the the_content() ?

    Will it still works?

  3. J Mehmett

    This works like a plugin, Nice trick! That’s why I hate plugins and do like to add everything from theme side.

    So, using filters and actions, child theme will work as a machine… Nice tip, friend.

  4. Darren Hoyt

    That’s a cool use of filters, Justin. These days I usually just include a file called ‘loop.php’ with my themes which uses a bunch of conditionals to determine content vs. excerpt depending on the page you’re on. I’m liking the idea of using filters now, though.

  5. Gustavo Ayres

    Hi Justin,

    This was exactly what I was looking for. I was trying to do something like that.
    The only problem I had is tha I use a plugin [can't remember the name] that I can add some BBCODE-like on my text and it makes a adsense banner appear. I put something like:

    [ad#banner-post]

    And it shows the banner.

    Using the code you put here, it doesn’t work anymore. Do you have any idea why it stopped work?

    Thanks in advance

  6. J Mehmett

    I was thinking about adding some extra code in your above code, so I could make the links in the post appear in the the_excerpt(); too as they appear in the the_content();. Because, the_excerpt(); doesn’t show links in the post by default. I’ll give it a try.

    Of course the more we use functions.php the less we need a plugin.

  7. edoluz

    Thanks again Justin!! Great work!!!

  8. Link Love and Updates September 14 | Unlock The Online World

    [...] 1. Nihar-How to group chat with GTalk 2. Tara- Social Network Rundown 3. WPCandy- Easier Theme Development With Sample Posts 4. Pearsonified-How You Can Use WordPress Functions to Run a Smarter Blog 5. Justin Tadlock-Replacing WordPress content with an excerpt without editing theme files [...]

  9. impNERD

    This would be much better served as a plugin. You could easily set what pages this should effect as well.

  10. Nihar

    Great tip. I will try to implement this.

    Thanks..

  11. baldo

    Sorry guys but Im not a php guy. I follow the abouve procedure and put the code “// Add filter…” and “function my_excerpts…” to mu function.php under my present theme. But could not get it to work.

    The article post still displays the whole article. Need help.

  12. baldo

    oh by the way, does it also filters even old posts? I wanted to reduce ALL articles on my blogs to show only a number of characters. Thanks

  13. Lucía

    Thanks!! This helped a lot, you made my day :D

  14. Sparrow

    Hey Justin,

    This looks like the perfect solution to what I want to do. But you will have to forgive me as I am a newbie to the WordPress world. That being said, I am a little frustrated that WordPress’s own documentation and then here doesn’t say *where* to add this code or in what files..? Did I miss something?? As I said I am new, but it is like everybody assume that you know where these functions are!

    If you could advise I would quite grateful for the time it will save me sifting through files.

    Many thanks in advance!

  15. Wordpress Blog Services - Most Wanted WordPress Hacks: 11 New Requests (2)

    [...] Justintadlock has the solution: WordPress filters [...]

  16. 11个新WordPress技巧 | Housne Space

    [...] Justintadlock有解决此问题的方法:WordPress filters [...]

  17. Barrett Golding

    great script, Justin.
    i added a linked-to-post ellipsis ($postlink) at the end of the excerpt:

    Deleted by admin. Please use character entities when posting code.

    to get it w/in the auto-added tags of the “optional excerpt”,
    i added the link to your script here::
    $content = apply_filters('the_excerpt', $content . $postlink);

    then i also added it you your “if no excerpt” script here:
    $content = '' . $content . $postlink . '';

    not sure if that’s the best way to do job, but it does work in both cases:
    http://hearingvoices.com/news/2008/

  18. Barrett Golding

    oh, forgot, i also removed your ellipsis here:
    array_push($words, '');

  19. Jauhari

    Hi Justin, Is it possible on the excerpt remove the Image only? and keep the other thing on the content just like the original?

  20. 11个备用的WordPress编程技巧 - 菠菜博

    [...] Justintadlock有解决此问题的方法:WordPress filters [...]

  21. 11个新而实用的 WordPress 技巧【下篇】 at 时间与空间的屋子

    [...] 中加入以下代码,告诉WP您想将 the_content() 过滤成自己定义的函数(可参考详细教程): // Add filter to the_content add_filter(’the_content’, [...]

  22. Brian Mecham

    This doesn’t seem to work when your front page is a static page and not the blog page… I assume I’ll need to replace is_front_page with something else? but what?

  23. Brian Mecham

    I guess I’ll reply to my own question since I figured it out… instead of is_front_page I put is_home – that’s in this part of the code in case you are wondering:
    // If is the home page, an archive, or search results
    if(is_home() || is_archive() || is_search()) :
    global $post;
    $content = $post->post_excerpt;

    This makes blog post excerpts when front page is static and blog page is a different page.

  24. Victor

    Very GOOD!

    Will try to use it!

    Thanks

  25. udyr.com » Blog Archive » links for 2009-02-07

    [...] Replacing WordPress content with an excerpt without editing theme files [...]

  26. DrJ

    Dude- you’ve saved my bacon. I’ve been struggling with the_content vs. the_excerpt as a n00b for the past few weeks, and your post made the “AHA!” bulb go off-

    Thanks very much!

  27. silicon guru » Blog Archive » Wordpress tips

    [...] excerpts in templates Cool plugins, including disabling formatting, twitter, article list Removing <p> tags 1 Removing <p> tags [...]

  28. 小人物大坏蛋 » WordPress新技巧11个

    [...] Justintadlock有解决此问题的方法:WordPress filters [...]

  29. 我想网 » Blog Archive » 11个新WordPress技巧

    [...] Justintadlock有解决此问题的方法:WordPress filters [...]

  30. Mike Jump

    Thanks, I will implement this on my new developed themes. Mike

  31. freedimensional

    Hi Justin,

    Hope you are all good.

    I wonder if you could post a short tutorial on how to swap the_excerpt with the_content (yes, I mean to do the opposite!) in my theme?

    I’d like my readers to see everything without excerpts, but can’t suss out how to replace the functions.

    Tom

  32. Praz

    Is it possible to remove the image from the_content() and display only the text in single.php. In which files should I make changes? Can someone help?

  33. 水煮网 » Blog Archive » 11个新WordPress技巧

    [...] Justintadlock有解决此问题的方法:WordPress filters [...]

  34. PM

    Thanks, this should help me with future wordpress projects.

  35. קולנוע ביתי

    I am a newbie and before l I ‘ve read this post I have been working inefficiency.
    Due to your post I found the solution.
    I will definitely be implementing that !

  36. 24 Inch Bar Stools

    Very good tutorial Justin.
    Thank you.Helped me a lot.

  37. מתנה לחגים

    I’ve made some searching before upgradung my blog from blogger to WP.
    Your post made me the feeling that I am going to enjoy WP while there are such tools, themes, frameworks and solutions as this one.
    Thanks

  38. Ronald Nunez

    Hi Justin, Thanks a lot for posting this I have been looking around for this filter and just read from your post. This is really great and hope you are well. Keep on posting.

  39. Marvin

    Thanks for the tutorial.

    How can I modify this so that I can pass a specific word count value if I don’t want to use the default?

  40. HDD

    This will help me a lot folks.

  41. Build WordPress Sites Fast With the Thematic Theme Framework | Es Developed - Fresh Website and Graphic Design

    [...] Replacing WordPress Content With an Excerpt in a Thematic Child Theme How to replace the_content() with the_excerpt()–without touching your theme files. [...]

  42. Edds

    Your post made me the feeling that I am going to enjoy WP while there are such tools, themes, frameworks and solutions as this one.
    I will definitely be implementing that !
    Thanks

  43. Andri

    Uhm… what is the different between content and excerpt… sounds strange for me, sory newbie right here :)

  44. Replace full post by excerpts on homepage without editing your theme files

    [...] to Justin Tadlock for this cool snippet! If you enjoyed this article, please consider sharing it! tweetmeme_style [...]

  45. Phil

    Thank you so much !

  46. baja hoodie

    I will use this on my new themes.

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.