Site logo

Archived topic

Is it possible to have Page Excerpts in the same way as Post Excerpts

3 replies · Started by Gillian on June 30, 2020

Viewing posts 1–4 of 4

Hi

I would like to be able to have Page Excerpts in the same way as we hove Post excerpts - really just to deal with some password protected pages where some of the information showing in the automatic capture shouldn't be on show. I read that it could be done, but the code supplied needs to be adapted for the appropriate theme.

Another 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 an 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.

Thanks

Hi there,

Where would the page excerpt be displayed?

There isn't an archive for pages like an archive/blog for posts.

Let me know :)

I want it to replace the meta data which appears below the page title eg in Google searches or if you send someone the link to the page via Whats App

Hi there,

are you using an SEO plugin as they generally provide a meta description which would be used for sharing content.

This archived topic is closed to new replies.