This post is a bit nostalgic as it references the first topic that I ever wrote about WordPress on a blog. A little over two years ago, I wrote a post called How to Activate Excerpts for Pages in WordPress Admin Panel which explains the work that I had done while migrating my custom theme from WordPress 2.3.3 to WordPress 2.5.
The post was updated when WordPress 2.9 came around because someone commented that the cool drag and drop feature wasn’t working with the 2.5 code. This morning, I updated the page again for WordPress 3.0 – probably for the last time ever!
The WordPress developers have been adding really cool functionality to the core for the soon-to-be-released 3.0. one of the features that I’m really excited about is custom post types. I was looking through the core this morning when I realized that some of the functions behind this feature would allow users to add excerpts to pages with a single line of code:
add_post_type_support( 'page', 'excerpt' );
Drop this line in your active theme’s functions.php file and you’re good to go… probably forever!
From 2.3 though 2.9 I have came up with 3 different methods for enabling excerpts for pages. Why? You ask. Easy answer: WordPress changed the html that displayed the excerpt’s meta box in the administration panels. The example above contains no html – It’s even small enough to post on Twitter – It will always use whatever html WordPress needs to function properly eliminating the need to update every other version.
Now that’s progress!



Thanks, this was very helpful! I couldn’t understand where the excerpt field had gone. Following your instructions I had it back in 20 seconds.
Thanks, that works also for PHP illiterates like me… :-)
Awesome snippet, I’d been using an extremely naggy plugin to add excerpts to pages, and adding one line to the functions.php is so much easier, thanks for sharing!
No problem! I agree, nothing beats one line of code ;)
This is great and just what I was looking for. Any idea’s how I could use this to display the page excerpt in my sidebar?
Many thanks
Thanks! This makes life a lot nicer. ^_______^
Thanks for posting this! I have a page on one site that has to be edited weekly. Saving it was making the excerpt disappear. I use excerpts in the theme, so every week I was logging into phpMyAdmin to put the excerpt back on that page. You saved me a lot of work.
That sounds like a nightmare… yikes! Really happy you do not have to do that anymore :)
Thank you for this tip. I helped me to get rid of plugins. With this I made great use of page excerpts for featured pages.
Glad you found it useful. I agree, it’s much better than using a plugin to accomplish the same task as they will most likely need maintenance in the future.
Michael, I respectfully request advice to get this working.
I’ve spent 25 minutes researching this topic. I found your fix above and edited functions.php for Weaver 2.0 theme in WordPress 3.1. I have logged out/in of the site and cleared cache. I have looked at available screen options and see nothing about Excerpts. I don’t see the excerpts at the bottom of the Edit Page screen.
Is there some additional edit I need to do to the theme, or other configuration somewhere, to actually show the excerpt in the Edit Page screen?
I have activated the ExcerptEditor Plugin which was my old workaround. But it seems messed up in WordPress 3.1 and I can remove it once I get your fix working.
Sorry if this is a dumb question. Thanks.
Not sure as to why this is not working for you. You’ve performed all of the tests that I would suggest already. As a last resort please try the following code. Could be a theme bug?
function _mychildtheme_setup() { add_post_type_support( 'page', 'excerpt' ); } add_action( 'after_setup_theme', '_mychildtheme_setup', 11 );Hi,
This should be obvious in wordpress codex, but isn’t. I used to always wonder why when pages are technically the same as posts, can’t we access such features.
What I wonder about is-
Can this function also add support for featured images, tags, etc for pages in similar ways?
Saurabh,
Sorry to hear that this is not as obvious as it should be in the codex. Please post links to the pages that you think this information should be on and I will do my best to edit them.
TIP: Anyone can edit the codex. If you find that something is missing, please add it!
FYI: Pages are NOT technically the same as posts. They are actually very different in many ways.
Absolutely! Personally, I would never use tags on pages or any post_type other than tags. Just check out the taxonomy’s full name “post_tag” and you should see why. This taxonomy is intended to be used for “posts” and I never use it for anything else.
Best wishes,
-Mike
I don’t understand why you would ever need an excerpt on a page?
Pages show up in many different archive pages including search. Many people want control over the excerpt. I’ve custom things with page excerpts in the past … excerpts ARE a part of the posts table. So I always activate them.
if this does not show up immediatley for you, then you might need to click on the ‘screen options’ (little tab near the top right of the page when you are viewing a page. there is a checkbox for Excerpts – the field only shows up when this is clicked (and you have added the line in the functions file)
Dear Mike,
Tim here. I have added the appropriate code from above as suggested, Have add the excerpt from a page. Published the page.
But what I go to the page in question it doesn’t show the excerpt.
If you go to: http://members,timothycaron.com
and click on the center tab in the top menu you will notice that when the page loads it shows the full content of each page not the excerpt.
Can you assist.
Thanks in advance
Tim
Hi Tim! You’ll have to modify your theme. You’ll need to use
the_excerpt()in the file that you want the page excerpt to display. I generally use this in search.php and page.php.Dear Michael,
To be honest I wasn’t expecting a response on an old post. Thank you.
I did as you requested, and replaced $content with $the_excerpt and now I have no content at all under the titles, but have the full page of the parent one.
Really strange.
Tim
No problem. I’m not sure what is going on in your theme … might be something custom? Please change $the_excerpt back to $content and then add:
wherever you would like the excerpt displayed. It is a function, not a variable.
Dear Mike,
Tim here. You are correct I am designing a custom page template for wordpress. I have added code below the loop to bring in the child page of the parent, and it’s the excerpt of the child page that I want to bring in.
Anyway you can help
I’ll attache the code below.
Thanks
Tim
$post->ID, ‘sort_column’ => ‘post_date’, ‘sort_order’ => ‘desc’ ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( ‘child_of’, $content );
?>
<a href="ID ); ?>”>post_title; ?>
Hi Tim,
I couldn’t help but butt in. I have used this solution in a couple of sites.
This is a problem that is independent of Michael’s solution.
here’s the code:
<article id="post-" >
<a href="" title="Continue reading post_title; ?>">post_title; ?>
post_excerpt; ?><a href="" title="Continue reading post_title; ?>" class="rmore" rel="bookmark">Read More
<?php
}
if($is_empty) { echo 'Eh! Nothing in here?'; } wp_reset_query(); ?>
That got royally truncated:
One more attempt:
<div id=”featured” class=”clearfix”>
<?php
$pg_ids= array(6,8,10,12);
foreach ($pg_ids as $pg_id){
$post=get_post($pg_id);
?>
<article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
<header><h2><a href=”<?php the_permalink(); ?>” title=”Continue reading <?php echo $post->post_title; ?>”><?php echo $post->post_title; ?></a></h2></header>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(array(226,226));
}
?>
<p><?php echo $post->post_excerpt; ?><a href=”<?php the_permalink(); ?>” title=”Continue reading <?php echo $post->post_title; ?>” class=”rmore” rel=”bookmark”>Read More</a></p>
</article>
<?php
}
if($is_empty) { echo ‘<p align=”center” style=”padding:5px; margin:0;”>Eh! Nothing in here?</p>’; } wp_reset_query(); ?>
</div>
<div id=”main”>
<?php get_template_part( ‘loop’, ‘index’ ); ?>
</div>
Dear Saurabh Shukla,
let me try this code again so you can see what I’m doing.
$post->ID, ‘sort_column’ => ‘post_date’, ‘sort_order’ => ‘desc’ ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( ‘child_of’, $content );
?>
<a href="ID ); ?>”>post_title; ?>
This portion of code brings in all the child pages of the parent page they are listed under.
It can’t be a list of page ID’s as you have. It’s generated dynamically.
Tim
use post_excerpt instead of post_content.
sorry for my earlier reply. i realise, it was pretty useless
<?php
$p_id = $post->ID;
//this gets the current page
$pages= get_posts(‘child_of’ => $p_id);
//this gets the child pages of current page in an object
//now you can run a for loop on each $pages as $page
and output $page->post_excerpt;
?>
Okay, that might not work, as well, I think get_posts deosn’t support the child_of argument.
You’d have to go roundabout.
first get the current page id the way above. then use this to get child pages
<?php
$p_id = $post->ID;
//this gets the current page
$pages= get_pages(array(‘child_of’ => $p_id));
//this gets the child pages of current page in an object
for each($pages as $pagg){
$childpg=$get_post($pagg->id);
//we have to again use get-post because get_page will ot get you the excerpt. so, yeah, roundabout is the way!
echo $childpg->post_excerpt;
}
?>
This must work
I’ve tried and tested it just now. It works! Let me know how it goes with you.
I meant in the last to last comment that get_pages doesn’t return the excerpt. get_posts doesn’t support child_of.
So, you use get_pages to get child pages. Loop through, get the id and use it with either get_post or get_page to get the excerpt.
Brilliantly simple. Thanks for sharing this useful tidbit!
This worked beautifully as a way feature new pages on the site. Thanks for finding this!
Works perfectly. Thanks for the great tip.
I always end up on your blog posts when googling for arcane WP tweakery. All roads lead to Rome.
I had a plugin that pulled from the excerpt, but no excerpt field! I added your one-liner, it worked.
You, sir, are my hero of the day!