How can you have it so that the site’s home page will only show the first X (let’s say 300) words of the post?
But without using “more” tag, or hand filled excerpts? I am looking for a plugin/hack for WP 2.9 and onward.
I came across several solutions so far, but am hoping for a recommended solution.
Challenges I came a cross so far:
- What happens in case a tag (for example ) starts on word 295, and ends after word 301 ?
- Can it be possible to have a different X for the home page , tags page, category page – and so on?
- Can the format of the text be preserved? (all the images and text formating)?
- Having the plugin take the least amount of recourses from the server.
Changing the word count on the home page is easy:
Just replicate that code and change the conditional check to add this to other pages. The other option is to just insert the code on the template page (
home.php
,tag.php
, etc.), so you know it’s going to be set on the correct page.Using
the_excerpt()
will automatically strip shortcodes and html from the content if there’s no excerpt provided. You can remove these filters, but it makes it much much harder to do word counts when you’re adding markup into the mix. If you want the formatting/text/images preserved, that’s what themore
tag is for. It’s inserted manually because it’s too difficult to automatically figure out in all instances where that break should go.You can use the Fancy Excerpt Plugin For WordPress for that and modify it a bit. It preserves the style, does word-counting. You just need to modify this a bit to have your word-count and maybe if you don’t like the ellipsis to modify the ending as well.
if you just need the first 300 words of the content you can easily get it with