73 Responses

  1. Dan Philibin
    Dan Philibin Published |

    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
    Pangeran Published |

    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
    J Mehmett Published |

    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
    Darren Hoyt Published |

    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
    Gustavo Ayres Published |

    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:


    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
    J Mehmett Published |

    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
    edoluz Published |

    Thanks again Justin!! Great work!!!

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

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

  10. Nihar
    Nihar Published |

    Great tip. I will try to implement this.


  11. baldo
    baldo Published |

    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
    baldo Published |

    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
    Lucía Published |

    Thanks!! This helped a lot, you made my day 😀

  14. Sparrow
    Sparrow Published |

    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)
  16. 11个新WordPress技巧 | Housne Space
    11个新WordPress技巧 | Housne Space at |
  17. Barrett Golding
    Barrett Golding Published |

    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:

  18. Barrett Golding
    Barrett Golding Published |

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

  19. Jauhari
    Jauhari Published |

    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编程技巧 - 菠菜博
  21. 11个新而实用的 WordPress 技巧【下篇】 at 时间与空间的屋子
  22. Brian Mecham
    Brian Mecham Published |

    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
    Brian Mecham Published |

    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
    Victor Published |

    Very GOOD!

    Will try to use it!


  25. udyr.com » Blog Archive » links for 2009-02-07
  26. DrJ
    DrJ Published |

    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
  28. 小人物大坏蛋 » WordPress新技巧11个
  29. 我想网 » Blog Archive » 11个新WordPress技巧
  30. Mike Jump
    Mike Jump Published |

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

  31. freedimensional
    freedimensional Published |

    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.


  32. Praz
    Praz Published |

    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技巧
  34. PM
    PM Published |

    Thanks, this should help me with future wordpress projects.

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

    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
    24 Inch Bar Stools Published |

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

  37. מתנה לחגים
    מתנה לחגים Published |

    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.

  38. Ronald Nunez
    Ronald Nunez Published |

    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
    Marvin Published |

    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
    HDD Published |

    This will help me a lot folks.

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

    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 !

  43. Andri
    Andri Published |

    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
  45. Phil
    Phil Published |

    Thank you so much !

  46. baja hoodie
    baja hoodie Published |

    I will use this on my new themes.

  47. Kim Lee
    Kim Lee Published |

    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?

  48. Why I am not a Hybrid Core User
    Why I am not a Hybrid Core User at |
  49. Display Wordpress Excerpt Automatically Rather Than Full Post
  50. Swamykant
    Swamykant Published |

    Nice trick. But I want to the reverse way ?

    1. Jonathan Sampson
      Jonathan Sampson Published |


      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

      Hope this helps.

  51. Keval
    Keval Published |

    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!

  52. Sarbjit Singh
    Sarbjit Singh Published |

    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.

  53. Scott Wyden Kivowitz
    Scott Wyden Kivowitz Published |

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

  54. Arick
    Arick Published |

    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?

  55. Manoj Shekhawat
    Manoj Shekhawat Published |


    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

    1. Ferdinand
      Ferdinand Published |

      Hi Manoj, this code below displays the link “read more”:

      // Add filter to the_content
      	add_filter('the_content', 'my_excerpts');
      function my_excerpts($content = false) {
      // If is the home page, an archive, or search results
      	if(is_front_page() || is_archive() || is_search()) :
      		global $post;
      		$content = $post->post_excerpt;
      	// If an excerpt is set in the Optional Excerpt box
      		if($content) :
      			$content = apply_filters('the_excerpt', $content);
      	// If no excerpt is set
      		else :
      			$content = $post->post_content;
      			$excerpt_length = 100;
      			$words = explode(' ', $content, $excerpt_length + 1);
      			$more = '[...] Read more';
      			if(count($words) > $excerpt_length) :
      				array_push($words, $more);
      				$content = implode(' ', $words);
      			$content = '' . $content . '';
      // Make sure to return the content
      	return $content;
  56. How to Display Excerpts on your Blog Homepage Instead of the Full Post
  57. Text auf der Startseite des WordPress Blogs automatisch begrenzen |PHP Archiv
  58. Ian Armstrong
    Ian Armstrong Published |

    Man, Justin, I can hardly believe this still solves a major problem, six years later. Bravo brother man. You’d think the core would have been made more flexible in this regard.

    I typically flip out the array_push($words, '...');


    array_push($words, '... <a>ID) . '">Continue to Article</a>');

    Which I find useful.

  59. ayyan
    ayyan Published |

    what is the easiest way to find the_content, if its not available in index.php or content.php file.?

  60. Ryan Hellyer
    Ryan Hellyer Published |

    Seven years since you wrote it, and this is still an extremely useful blog post. Thanks 🙂

  61. Excerpts and not full content, but only sometimes | Mostly Harmless
  62. ULVEN | Frontend Design and Development
    ULVEN | Frontend Design and Development at |
  63. DBP
    DBP Published |

    Love it! This solved an issue for me where there were instances of custom excerpts that I wanted to overwrite with automated excerpts. Thanks!

  64. SoulRiser
    SoulRiser Published |

    Thank you! 10 years later, this still works perfectly. Much better than installing random plugins with ‘upgrade to pro’ nags.

    I just with the search engines would bless this post with the #1 result spot in searches.

  65. Francois
    Francois Published |

    Hello guys,

    Gosh your code seems pretty cool to use.. It’s a shame I don’t understand it completely 🙂

    I landed on this article because I’m trying to achieve something “special” with my excerpt.

    I intend to write a excerpt for all my posts. I intend : filling with text the field box called “excerpt” under the article in the admin panel.

    What I want to do is to call this text for the excerpt on my homepage but display the excerpt generated by WP when the posts are displayed on other pages (category and so on).

    Have you ever done something like this ?

    Thanks a lot

    ps : I want to do this instead of “simply” reduce the length of the excerpt on the homepage, category page, and so on..

Comments are closed.