How To Add Excerpts To Your Pages In WordPress

Why add excerpts to pages in WordPress?

WordPress comes with posts and pages as two types of default content. Messages are displayed in reverse chronological order (from last to oldest) on your blog or home page.

Pages, on the other hand, are self-contained content that is not published in a specific order. They are usually used for one-time content, for example, about us or for a contact page.

Sometimes you may need to display passages for your pages.

Let’s take a look at how to add passages to your pages in WordPress, as well as how to display these passages on your site.

Add snippet to pages in wordpress

First you need to add the following code to the file. functions.php your theme or plugin for a specific site.

add_post_type_support ('page', 'excerpt');

This code modifies the default WordPress content type ‘page’ to add support for excerpts.

You can go to create a new page or edit an existing page. Below the post editor you can see the window for the passage.

Excerpt metabox on the page editing screen in WordPress

Now you can use this window to add custom passages for your pages in WordPress.

Read: Managing Widgets in WordPress

Display passages for pages in wordpress

There are many different ways to display excerpts for your pages in WordPress. Depending on what you are trying to do on your website, you can choose the method that best suits your needs.

Method 1: View recent pages using statements using Shortcode

This method allows you to create your own custom queries and display the last pages using shortcodes.

First you will need to install and activate the plugin. Shortcode Display Posts.

After activation, you need to edit the message, page or widget where you want to display the last pages, and add the following shortcode.

[display-posts post_type="page" include_excerpt="true" excerpt_more="Continue Reading" excerpt_more_link="true"]

This shortcode will display the last 10 pages with their title, excerpt, and a link to continue reading.

If you do not specify a custom passage for the page, it automatically generates a passage for a page with a default length of 55 words.

If you are using a shortcode in the sidebar widget, you may need to enable shortcode support for the text widget. Just add this code to the file. functions.php your topic.

add_filter ('widget_text', 'do_shortcode');

Method 2: Display the page snippet in the sidebar using the plugin

This method allows you to easily display the last pages and their passages in the sidebar of your topic.

First you need to install and activate the Ultimate Posts Widget widget.

After activation you need to go to the page “Appearance” Widgets and add Ultimate Posts widget on the sidebar.

First you need to specify the title for the widget, and then go to the “Display” tab.

Show excerpt for pages in widgets

Then you need to select the “Show excerpt” option, and then go to the filter tab.

On the filter tab, select “Page” in the “Message Types” section, and then click the “Save” button to save the settings.

Select page as message type

Now you can visit your website to see the result in action.

Method 3: Manual page fragments

Another way to display excerpts from a page is to add code directly to the topic files. You can create your own page template and add the following code to it.

$ args = array (
'post_type' = & amp; gt; array ('page'),
'posts_per_page' = & amp; gt; ten,
// The Query
$ the_query = new WP_Query ($ args);
// The Loop
if ($ the_query- & amp; gt; have_posts ()) {
while ($ the_query- & amp; gt; have_posts ()) {
$ the_query- & amp; gt; the_post ();
echo '& lt; h3 & amp; gt;'. get_the_title (). '& lt; / h3 & amp; gt;';
the_excerpt ();
/ * Restore original Post Data * /
wp_reset_postdata ();
} else {
// no posts found

That’s all

Leave a Reply

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