1

I'm building a custom child theme using the Twenty Nineteen default WordPress theme as the parent.

I added some text in the excerpt section available in the Editor as follows:

enter image description here

But the full content of each post is displayed on the blog/posts page instead of just the excerpt.


What is the proper way of adding/using excerpts in the new Gutenberg editor?

  • Are you trying to display only the excerpt on the front-end or in Gutenberg itself? – phatskat Feb 2 at 22:29
  • @phatskat In the front-end blog page. – AndrewL64 Feb 2 at 22:30
  • One more question - is this for single pages or the blog post list page? Also, which theme are you using? – phatskat Feb 2 at 22:46
0

you need modify your template, in your PHP change the_content() to the_excerpt()

This php functions print the content and the excerpt respectively

0

You should use a custom page for this. For reference, we can modify the default (twentynineteen) post content block. Depending on your theme, you may need to modify single.php, or a content block included from there. In the twentynineteen theme, we can see this on line 24:

get_template_part( 'template-parts/content/content', 'single' );

Following that, we can look into template-parts/content/content-single.php at line 23:

 23         the_content(
 24             sprintf(
 25                 wp_kses(
 26                     /* translators: %s: Name of current post. Only visible to screen readers */
 27                     __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentynineteen' ),
 28                     array(
 29                         'span' => array(
 30                             'class' => array(),
 31                         ),
 32                     )
 33                 ),
 34                 get_the_title()
 35             )
 36         );
 37  

So, you could replace this call to the_content with something like this:

the_excerpt(); // Echo the excerpt directly.
$excerpt = get_the_excerpt(); // Store the excerpt in $excerpt.

// Retrieve the "raw" exceprt - this has not passed any filters etc,
// and instead comes directly from the database.
$post = get_post();
echo $post->post_excerpt;
0

The twentynineteen front page is controlled by the file /wp-content/themes/twentynineteen/index.php. It contains the code

while (have_posts()) {
  the_post();
  get_template_part('template-parts/content/content');
}

This code applies the template part in template-parts/content/content.php. Change content to content-excerpt so that your code looks like this

while (have_posts()) {
  the_post();
  get_template_part('template-parts/content/content-excerpt');
}

Now template-parts/content/content-excerpt.php is applied instead, which is what you want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.