Add Excerpts to Pages and Posts in WordPress

HL News • January 3, 2014

So you’ve got your excerpt working great in your posts. You’ve figured out that if you didn’t see it by default, you clicked on screen options and enabled it. Now, where is it inside pages? By default excerpts are not enabled in WordPress for pages, but luckily there is a simple function you can add to your functions.php file to enable Page Excerpts.

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}

Now you will see the Excerpt box below the Content box on your pages. If you don’t see it immediately, check your screen options and make sure that the excerpt box is selected.

To add this to your pages, as I have done on this site under the page title, just add:

to your page.php file or page template file. Now that you have the excerpt working, you may notice that when clicking on the link, the page scrolls to the section where you left off. But, again there could be instances where you just want the page to be displayed, without the scroll. Add this to your function.php file to stop the scroll:

function remove_more_link_scroll( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', $link );
return $link;
}
add_filter( 'the_content_more_link', 'remove_more_link_scroll' );

For more information about the add_post_type_support function, check out the WordPress Codex. Happy Coding!