Would you like to include Excerpts on your WordPress pages?
Excerpts are short excerpts from your material that can be used to offer a description, summary, or other information to a page. Excerpts are only accessible for posts in WordPress by default.
We’ll show you how to add excerpts to your WordPress pages in this article.
Why Would You Want to Include Excerpts in WordPress Pages?
Posts and pages are the two default content kinds in WordPress. On your blog or homepage, posts are shown in reverse chronological order (newest to oldest).
Pages, on the other hand, are standalone pieces of content that aren’t published in any particular order. They’re usually reserved for one-time material, such as your about us or contact pages.
You may need to show extracts for your pages on occasion. Especially if you’ve solely used pages to create your WordPress site.
Let’s look at how to add excerpts to your WordPress pages and how to show them on your website.
Adding Excerpt to WordPress Pages
To begin, add the following code to your theme’s functions.php file or a site-specific plugin’s functions.php file.
1
|
add_post_type_support( 'page' , 'excerpt' ); |
This code adds support for excerpts to the basic WordPress content type ‘page.’ Please visit our guide on how to add custom code to WordPress for more information.
After you’ve added the code to your website, you can go ahead and create a new page or change one that already exists. You’ll notice the ‘Excerpt’ meta box in the panel on your right once you’re in the WordPress article editor.
You can now utilize this excerpt meta box to add custom excerpts to your WordPress blog’s pages.
Using WordPress to Show Excerpts from Pages
In WordPress, you may display excerpts for your pages in a variety of ways. You can choose the strategy that best meets your needs depending on what you’re attempting to accomplish with your website.
Method 1: Using a shortcode, show recent pages with excerpts.
This solution allows you to construct your own custom queries and use a shortcode to display recent pages.
The Display Posts Shortcode plugin must first be installed and activated. See our step-by-step guide on installing a WordPress plugin for more information.
You must change the post, page, or widget where you wish to display recent pages after activation and include the following shortcode.
1
|
[display-posts post_type="page" include_excerpt="true" excerpt_more="Continue Reading" excerpt_more_link="true"] |
This shortcode will show ten recent pages, each with a title, excerpt, and a link to continue reading.
If you don’t specify a custom excerpt for a page, the page’s excerpt will be generated automatically with a length of 55 words.
You may need to enable shortcode support for the text widget if you’re using the shortcode in a sidebar widget. Simply paste this code into the functions.php file of your theme.
1
2
|
// Enable shortcodes in text widgets add_filter('widget_text','do_shortcode'); |
Method 2: Use a plugin to display page excerpts in the sidebar.
This solution makes it simple to display recent pages and excerpts in the sidebar of your theme.
The MK Post and Page Excerpts Widgets must first be installed and activated. See our step-by-step guide on installing a WordPress plugin for more information.
To add the MK Post and Page Excerpts Widgets block to a sidebar, go to Appearance » Widgets and click the ‘+’ button after activation.
You can choose your page from the dropdown menu under Select Page after you’ve added the widget block.
There are other options to change the title, pick whether or not the page title should be displayed, alter the content, define the content length, add a featured image, and more.
When you’re finished, go to the top and click the ‘Update’ button. You can now see the widget in action on your website.
Method 3: Manually display page excerpts
Adding the code straight to your theme files is another option to display page excerpts. You can start by creating a custom page template and inserting the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
$args = array ( 'post_type' => array ( 'page' ), 'posts_per_page' => 10, ); // The Query $the_query = new WP_Query( $args ); // The Loop if ( $the_query ->have_posts() ) { while ( $the_query ->have_posts() ) { $the_query ->the_post(); echo '<h3>' . get_the_title() . '</h3>' ; the_excerpt(); } /* Restore original Post Data */ wp_reset_postdata(); } else { // no posts found } |
You’ll have to change the code to fit your theme’s templates.
We hope this post has shown you how to add excerpts to your WordPress pages. You might also be interested in our guide to selecting the best website builder or our expert recommendation for the best live chat software.