How to Remove Astra Post Excerpt from the Post Archive
|
/ Documentation /Customizer Settings/Blog/ How to Remove Astra Post Excerpt from the Post Archive

How to Remove Astra Post Excerpt from the Post Archive

Astra is a popular WordPress theme known for its flexibility and customization options. However, sometimes you might want to make specific changes to its default behavior.

One common customization request is to remove the post excerpt from the post archive pages.

In this document, we’ll guide you through the process of achieving this with a simple code snippet.

Why Remove the Post Excerpt?

Post excerpts are brief summaries of your blog posts that appear on archive pages like category, tag, and author archives. While they can be useful, there are situations where you might prefer not to display the post excerpt.

Perhaps you want to focus solely on the post titles and featured images, or you have a specific design in mind that doesn’t require excerpts.

How to Remove Astra Post Excerpt from the Post Archive

To remove the post excerpt from Astra’s post archive pages, you can follow the below-mentioned steps.

  • Log in to your WordPress admin panel using your credentials.
  • In the WordPress dashboard, go to “Appearance” and select “Theme File Editor.”
  • In the Theme Editor, you should see a list of theme files on the right. Locate and select the `functions.php` file from the list.
  • Inside the `functions.php` file, you can add the following code snippet:
add_filter( 'the_excerpt', 'filter_the_excerpt', 10, 2 );
    function filter_the_excerpt( ) {
    return ' ';
 }
  • After adding the code snippet, click the “Update File” button to save your changes.
How to Remove Astra Post Excerpt from the Post Archive

We have documentation on how to add custom codes. This document will assist you in better understanding it. Here’s the link https://optimization.bsf.io/docs/add-custom-php-code/.

This code uses the add_filter function to hook into the the_excerpt filter. It checks if the current page is an archive page (like category, tag, or author archives)

If it is, the code returns an empty string, effectively removing the post excerpt from those pages.

Once you update the code, then visit one of your post archive pages on your WordPress site, and you’ll notice that the post excerpts are no longer displayed.

Your archive pages will now show only post titles and featured images, or whatever other content you have on your archive pages.

Additionally, there may be instances when you wish to retain the “Read More” button while removing the excerpt. In such cases, you can include the custom code attached below in the functions.php file.

add_filter( 'the_excerpt', 'filter_the_excerpt', 10, 2 );
function filter_the_excerpt( $excerpt ) {
    // Return an empty string to remove the excerpt text
    $excerpt = '';

    // Add the "Read more" button HTML
    $excerpt .= '<a class="ast-button" href="' . esc_url( get_permalink() ) . '">' . esc_html__( 'Read More', 'astra' ) . '</a>';

    // Return the modified excerpt
    return $excerpt;
}

Once you update the code, then visit one of your post archive pages on your WordPress site, and you’ll observe that the post excerpts are now hidden, and in their place, you’ll find the “Read More” button prominently displayed.

Note: Remember to make any changes to your theme’s files with caution, and always keep a backup of your site in case anything goes wrong. If you have any questions or need further assistance, leave a comment below.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form