61 Responses

  1. Dan Philibin
    Dan Philibin August 24, 2008 at 7:22 am |

    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?

    Reply
  2. Pangeran
    Pangeran August 24, 2008 at 7:27 am |

    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?

    Reply
  3. J Mehmett
    J Mehmett August 24, 2008 at 7:55 am |

    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.

    Reply
  4. Darren Hoyt
    Darren Hoyt August 24, 2008 at 11:31 am |

    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.

    Reply
  5. Gustavo Ayres
    Gustavo Ayres August 24, 2008 at 12:42 pm |

    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

    Reply
  6. J Mehmett
    J Mehmett August 24, 2008 at 9:37 pm |

    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.

    Reply
  7. edoluz
    edoluz August 25, 2008 at 2:15 am |

    Thanks again Justin!! Great work!!!

    Reply
  8. Link Love and Updates September 14 | Unlock The Online World
  9. impNERD
    impNERD September 24, 2008 at 4:12 pm |

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

    Reply
  10. Nihar
    Nihar September 25, 2008 at 11:20 pm |

    Great tip. I will try to implement this.

    Thanks..

    Reply
  11. baldo
    baldo September 29, 2008 at 4:46 am |

    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.

    Reply
  12. baldo
    baldo September 29, 2008 at 4:49 am |

    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

    Reply
  13. Lucía
    Lucía October 30, 2008 at 7:47 am |

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

    Reply
  14. Sparrow
    Sparrow November 17, 2008 at 6:42 am |

    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!

    Reply
  15. Wordpress Blog Services - Most Wanted WordPress Hacks: 11 New Requests (2)
  16. 11个新WordPress技巧 | Housne Space
    11个新WordPress技巧 | Housne Space November 26, 2008 at 2:11 am |
  17. Barrett Golding
    Barrett Golding December 6, 2008 at 10:15 am |

    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/

    Reply
  18. Barrett Golding
    Barrett Golding December 6, 2008 at 10:16 am |

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

    Reply
  19. Jauhari
    Jauhari December 20, 2008 at 7:00 pm |

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

    Reply
  20. 11个备用的WordPress编程技巧 - 菠菜博
  21. 11个新而实用的 WordPress 技巧【下篇】 at 时间与空间的屋子
  22. Brian Mecham
    Brian Mecham December 29, 2008 at 3:30 am |

    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?

    Reply
  23. Brian Mecham
    Brian Mecham December 29, 2008 at 3:40 am |

    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.

    Reply
  24. Victor
    Victor February 4, 2009 at 3:40 pm |

    Very GOOD!

    Will try to use it!

    Thanks

    Reply
  25. udyr.com » Blog Archive » links for 2009-02-07
  26. DrJ
    DrJ February 22, 2009 at 10:19 pm |

    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!

    Reply
  27. silicon guru » Blog Archive » Wordpress tips
  28. 小人物大坏蛋 » WordPress新技巧11个
  29. 我想网 » Blog Archive » 11个新WordPress技巧
  30. Mike Jump
    Mike Jump May 27, 2009 at 7:10 am |

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

    Reply
  31. freedimensional
    freedimensional June 6, 2009 at 5:45 pm |

    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

    Reply
  32. Praz
    Praz June 15, 2009 at 9:01 am |

    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?

    Reply
  33. 水煮网 » Blog Archive » 11个新WordPress技巧
  34. PM
    PM July 28, 2009 at 9:02 pm |

    Thanks, this should help me with future wordpress projects.

    Reply
  35. קולנוע ביתי
    קולנוע ביתי August 22, 2009 at 9:03 am |

    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 !

    Reply
  36. 24 Inch Bar Stools
    24 Inch Bar Stools August 22, 2009 at 12:13 pm |

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

    Reply
  37. מתנה לחגים
    מתנה לחגים August 25, 2009 at 6:01 am |

    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

    Reply
  38. Ronald Nunez
    Ronald Nunez September 8, 2009 at 7:57 am |

    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.

    Reply
  39. Marvin
    Marvin September 10, 2009 at 10:47 am |

    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?

    Reply
  40. HDD
    HDD September 26, 2009 at 2:27 am |

    This will help me a lot folks.

    Reply
  41. Build WordPress Sites Fast With the Thematic Theme Framework | Es Developed - Fresh Website and Graphic Design
  42. Edds
    Edds November 6, 2009 at 10:50 am |

    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

    Reply
  43. Andri
    Andri November 29, 2009 at 7:27 am |

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

    Reply
  44. Replace full post by excerpts on homepage without editing your theme files
  45. Phil
    Phil March 9, 2010 at 8:21 am |

    Thank you so much !

    Reply
  46. baja hoodie
    baja hoodie March 12, 2010 at 5:29 am |

    I will use this on my new themes.

    Reply
  47. Kim Lee
    Kim Lee October 7, 2010 at 3:45 am |

    Hi Justin,
    I am changing the_content with the_excerpt on almost every blog that I make. Naturally I have to repeat it on every new theme I upload and test. If I understood the benefit of your approach correctly, by making this adjustment, every theme that I upload to my blog will automatically display excerpt instead of content on the archives, front page and search page. Did I understand it correctly?

    Reply
  48. Why I am not a Hybrid Core User
    Why I am not a Hybrid Core User November 17, 2010 at 7:13 pm |
  49. Display Wordpress Excerpt Automatically Rather Than Full Post
  50. Swamykant
    Swamykant March 23, 2011 at 5:04 pm |

    Nice trick. But I want to the reverse way ?

    Reply
    1. Jonathan Sampson
      Jonathan Sampson July 12, 2011 at 2:15 pm |

      Swamykant,

      Reversing it (delivering the_content in the place of the_excerpt) is even easier since there’s no danger of recursive calls:

      // Anytime my theme calls the_excerpt()`, call myCustFunct()
      add_action( 'the_excerpt', 'myCustFunc' );
      function myCustFunc ( $data ) {
        // Spit out the_content(), disregarding $data
        the_content();
      }

      Hope this helps.

      Reply
  51. Keval
    Keval August 10, 2011 at 2:16 pm |

    Thank you so much! I recently had to reinstall my theme due to a coding mess error in the header.php, and when I reinstalled, I noticed my home page was out of whack because my previous coding had not been saved.

    I new integrating an excerpt was the only way, and this was the only set of instructions that worked perfectly for me. Thanks again!

    Reply
  52. Sarbjit Singh
    Sarbjit Singh November 2, 2011 at 1:24 pm |

    You just saved me from editing my theme. I use child themes, so just needed to change one line of code. However, it is always better to do things with filters.

    Reply
  53. Scott Wyden Kivowitz
    Scott Wyden Kivowitz June 8, 2012 at 3:23 pm |

    Is there an additional script that can be included to have the featured image thumbnail show as well?

    Reply
  54. Arick
    Arick August 2, 2012 at 11:25 pm |

    I’m trying to print the description of the category (via Edit category and then fill the description) to show up in category but it always fail. The category only show an excerpt of posts and not the description of the category. I would like to show the description first and then excerpt.
    Maybe using filters will make it work. Any ideas?

    Reply
  55. Manoj Shekhawat
    Manoj Shekhawat November 18, 2012 at 11:49 pm |

    Awesome;

    Just want to know if we can add a link to complete post just after the Excerpt (Read More). I am a designer and it will be a big help if you can let me know the code line for the same

    Reply
  56. How to Display Excerpts on your Blog Homepage Instead of the Full Post

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.