Customize WordPress excerpts and ‘more’ link in WordPress 2.9

On many of mine or other magazine type of WordPress themes, you would see the homepage displaying blocks of post excerpts. These excerpts are generated using the template tag

<?php the_excerpt(); ?>

By default this template tag returns the first 55 words of the post’s content. This teaser is generated only if you have not specified any custom excerpt from your post editor section. But what if you want to display more than 55 words on your excerpts? Simple, just add the following code to your theme function.php file. It will return first 100 words of post’s content.

function new_excerpt_length($length) {
	return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

What about the […] string at the end of excerpt


By default WordPress excerpts shows a […] string at the end of the excerpt. what if you want to change this to a link. something like [Read More] which links to full post view.To do that just add the following code to your functions.php file.

function new_excerpt_more($more) {
return '<a href="'. get_permalink($post->ID) . '">' . ' [Read More]' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Reference: WordPress Codex

  • Hi, this was just wonderful, now we can wholly customize our wordpress themes as we want.

  • Hi, this was just wonderful, now we can wholly customize our wordpress themes as we want.

  • Selcuk

    Wow just wan´t to say, your themes are incredible! The most beautiful themes I´ve ever seen!

  • Selcuk

    Wow just wan´t to say, your themes are incredible! The most beautiful themes I´ve ever seen!

  • darkporn

    thanks. i really have no idea what is excerpt until now..

  • thanks. i really have no idea what is excerpt until now..

  • super god :))))))) beautiful themes

  • Well , the view of the passage is totally correct ,your details is really reasonable and you new balance 996 guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!

  • “Here elaborates the matter new balance shoes not only extensively but also detailly .I support the
    write’s unique point.It is useful and benefit to your daily life.You can go those
    sits to know more relate things.They are strongly recommended by friends.Personally

  • Yeah. . word press really helps me a lot. thanks for the info.

  • Chrissin2

    I have the code in the Falcon theme but it still shows the […} how to fix?

  • Chrissin2

    I have the code in the Falcon theme but it still shows the […} how to fix?

  • This is great! I think reading this, I loved every word. Seriously, keep posting the good information, bloggers like myself need it.

  • Tim Henderson

    Thank you for the “Scarlett theme, but I am having trouble changing the Header? I thought there would be a Header option- in the Scarlett Options ….I will give it a go.

    Thank you
    Tim

  • Vicky

    I use WordPress Version 3 somthing and I can’t seem to get the excerpt length changed, I’ve edited all places where 55 occurs and also added the code to functions.php file and still no joy, any idea what might be wrong?
    Thanks

  • Sandinosaso

    Nice post.
    Here is one about modal links (links to images that open the image in a fancy modal window):http://sandinosaso.webcindario.com/

  • I don’t use WP excerpt and don’t know how to use it. But now I got it.

  • I have a question thats driving me nuts. Sometimes the homepage post titles may be 50 characters or more…when this occurs it makes the post blocks uneven. How can I correct this problem so that it shows evenly regardless of the length of the post title ?
    Heres an example:
     http://paraspiracy.com/home/

  • Thanks for showing how to do this… as customizeable as WordPress is I’m constantly surprised by issues like this where it would seem like this option should be part of settings inside the admin deal… is there a concern with making your excerpts longer? It doesn’t impact RSS or Atom Feeds does it?

  • So am I the only one confused here? What file do I need to make this change in?