Excerpt For WordPress Pages

One thing that repeatedly annoys me when attempting to use WordPress as a CMS is the lack of an excerpt field on the Page editor. Happily, it only takes 10 seconds to fix.

Wordpress Pages are just another post type stored within the posts table, and so has all the same data fields as a post, except that WordPress in their wisdom have decided we don’t need access to them all.

Putting the standard Excerpt input area on the page editor just requires the following few lines in your theme’s function.php.

function page_editor_excerpt() {
global $post;
?>
<label class="screen-reader-text" for="excerpt">Excerpt</label><textarea rows="3" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt; ?></textarea>
<p>Excerpts are optional hand-crafted summaries of your content that can be used in your theme. <a href="http://codex.wordpress.org/Excerpt" target="_blank">Learn more about manual excerpts.</a></p>
<?php
}

function page_editor_init() {
//adds the Excerpt area on the page editor.
 if (is_callable('add_meta_box')) {
   add_meta_box('postexcerpt', 'Excerpt', 'page_editor_excerpt', 'page', 'normal', 'core');
 }
}
add_action('admin_init', 'page_editor_init');

This will put the Excerpt box on the page editor screen right where you expect to see it. Because the same code is used to save both pages and posts – only the “post_type” field is different – WordPress will automatically save the excerpt simply because $_POST['excerpt'] exists when posting the editor screen. If only everything was this simple!

You can also turn this into a plug-in if you don’t want to edit your functions.php file.

This entry was posted in Wordpress and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>