Pages is one of WordPress’ main content types, but doesn’t make use of excerpts. There are a couple of reasons why developers might need this field in WordPress pages. This post will show you how.
This is an ongoing post. Please suggest corrections, explanations, etc. in the comment section at the bottom of this page.
Excerpts are most of the time used as a Post summary. By default, excerpts in WordPress are only available for Posts. For most WordPress websites this will be enough as Pages are generally used for once-off content that is mostly not shown under the latest site content. Pages are, however, often included in the site’s search section, where a nice formatted (or custom) excerpt will fit in better with the rest of the site.
Activating excerpts for Pages
To activate excerpts for Pages in WordPress, the following function code needs to be added to the (child) theme’s
add_post_type_support( 'page', 'excerpt' );
This code will modify the default WordPress content type ‘Page’ to add support for excerpts. Once the
functions.php is updated, new and existing Pages will show an excerpt meta box.
If this box is left empty, WordPress will still generate its own excerpt based on the first text in the content section. By adding a custom excerpt to this section, WordPress will use that one in stead.
Using WordPress Page excerpts
Adding custom excerpts to Pages will often be enough for WordPress to automatically start using them in the default areas of rest of the site. For WordPress websites that makes frequent use of Pages, developers might want to use Page excerpts in their content.
The default PHP code for calling Page excerpts in WordPress is exactly the same as for calling excerpts for Post:
<?php echo get_the_excerpt(); ?>
Behind the Scenes is a free, informative website. If you find value in any of our content, please consider making a donation to our cause.
About the author
Renier busies himself with improving his English writing, creative web design and his websites, photoshopping, micro-electronics, multiple genres of music, superhero movies and badass series.
Save, share & Disqus
Use the buttons below, on the left or the bottom of this page to share this post. Your comment is important, but don't be a knob. Keep it constructive and polite.
Comment via Disqus
Disqus is a worldwide comment hosting service for web sites and online communities. This secure platform ensures a pleasant commenting environment which is manageable from one account. Use the Login button to sign up.
More website development related posts
Using shortcodes in WordPress like a boss
2 February 2019
One of the many handy features in WordPress is its shortcode functionality. Shortcodes come in many shapes and sizes, but ultimately it is like using a shortcut to display larger pieces of code. This post will go through some very basic principles of creating and using shortcodes in WordPress.
Using the Media Library Assistant plugin for WP
5 January 2019
WordPress websites with a large amount of Media content can become overwhelming to manage. With expanding libraries, images and other media can start to disappear in a sea of files which can make finding them very difficult. With the Media Library Assistant plugin for WordPress, searching and organising Media files becomes a breeze.
Disabling the Gutenberg Editor in WordPress 5
9 December 2018
Most WordPress users are probably happy with regular updates on their favourite content management website software, but for me, a striking difference starting at WordPress 5 was the Gutenberg Editor instead of the, now, Classic Editor. Without going into to much of a discussion, this post will show how disable the Gutenberg Editor.
Using WP’s “the_content” function and filter
12 July 2018
When the the_content() function is called in WordPress template files, the entire content of the post or page is displayed. By hooking some code in the form of a function into the the_content filter, the content can have custom HTML added in various ways.