How to add except in page. - WPTRINITY

How to add except in page.

By default, excerpts in WordPress are only available for posts.  we will show you how to add excerpts to your pages in WordPress. Sometimes you may need to display excerpts for your pages.

Adding Excerpts to Pages in WordPress

First you need to add the following code to your theme’s functions.php file.

1add_post_type_support( 'page', 'excerpt' );

This code modifies the default WordPress content type ‘page’ to add support for excerpts.
After adding code in function.php you see inside the page excerpt option.

Adding Excerpts to Pages in WordPress

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

1add_post_type_support( 'page', 'excerpt' );

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

Display Page Excerpts Manually

Way to display page excerpts is by adding the code directly to your theme files. You can create a custom page template and add the following code as a starting point.

 $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 will need to adjust the code to match your theme templates.

Leave a Comment

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