Categories
Uncategorized

How to add the excerpt box for pages in WordPress

Here’s how to enable the “excerpt” box for your WordPress pages.

By default, the WordPress post editor has an excerpt box that helps you add a little description to your posts. However, this option is not enabled by default for pages, so here’s the solution to that problem.

Add an excerpt meta box to pages

Pre-WordPress 3.0

The best way to add a meta box for pages in WordPress installs older than 3.0 is via the add_meta_box() function.

Add this code to your theme’s functions.php file:

<?php
function add_page_excerpt_support(){
   add_meta_box('postexcerpt', __('Page Excerpt'), 'post_excerpt_meta_box', 'page', 'advanced', 'core');
}

add_action('admin_init', 'add_page_excerpt_support');
?>

The code above tells WordPress to use the same “post_excerpt_meta_box()” callback function it employs to add the excerpt box for regular posts, to enable for pages as well.

 

WordPress 3.0 and up

WordPress 3.0 formally introduced support for new custom post types, which allow you to add custom content types besides the default “post” and “page” types. Along with this, the add_post_type_support() function was added to allow us to tell WordPress what “default” features we want a specific post type to support. Fortunately, we can use this to further extend the default “page” post type as well, such as adding an excerpt box to it.

Add this code to your theme’s functions.php file:

<?php
function add_page_excerpt_support(){
   add_post_type_support( 'page', 'excerpt' );
}

add_action('admin_init', 'add_page_excerpt_support');
?>

And that should be it! Now you should have a spankin’ new excerpt box ready to be filled on your WordPress page editor!

2 replies on “How to add the excerpt box for pages in WordPress”

Hi faltumsg,

Thanks for the contribution. This is a great way to get the excerpt once it has been added to a page. Cheers!

Leave a Reply

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