How to Add Meta Description as Excerpt in GeneratePress?

In this tutorial, we’ll learn how to add meta descriptions as excerpt in GeneratePress theme. This can be a useful technique for optimizing your website’s search engine rankings and providing users with a more informative preview of your content.

In this article, you’ll learn:

  • Use Rank Math or Yoast SEO meta descriptions as excerpts in GeneratePress
  • Customizing the “Read More” link at the end of the excerpt

Steps to Add Meta Description as Excerpt in GeneratePress

Here’s how you can add meta descriptions as excerpt in GeneratePress Theme, if you are using either the Rank Math or Yoast SEO plugin.

Here we are using the Code Snippets plugin to insert code in functions.php rather than creating a child theme in GeneratePress Theme.

Step 1: Install the Code Snippets plugin

  • Log in to your WordPress dashboard
  • Navigate to Plugins > Add New
  • Search for “Code Snippets“
  • Click “Install Now” and then “Activate”

Step 2: Add a new code snippet

  • Go to Snippets > Add New
  • Give your snippet a descriptive name (e.g., “Meta Description as an Excerpt in GeneratePress”)
  • Paste the following code into the “Code” section
  • Click “Activate” to save your changes

Check the code below for Rank Math or Yoast SEO.

Use Rank Math Meta Description as an Excerpt

If you are using Rank Math as SEO Plugin then you can use the following code.

/**
 * Use Rankmath meta description as excerpt
 */
function rankmath_description_as_excerpt( $excerpt ) {
    if ( ! is_admin() && has_excerpt() ) {
        return $excerpt;
    }

    $description = get_post_meta( get_the_ID(), 'rank_math_description', true );

    if ( ! empty( $description ) ) {
        $excerpt = wp_strip_all_tags( $description );
        $excerpt .= '

‘ . apply_filters( ‘rankmath_description_as_excerpt_more', __( ‘Read More', ‘your-text-domain' ) ) . ‘

‘; } return $excerpt; } add_filter( ‘get_the_excerpt', ‘rankmath_description_as_excerpt' );

Use Yoast SEO Meta Description as an Excerpt

If you are using Yoast as an SEO Plugin then you can use the following code

/**
 * Use Yoast SEO meta description as excerpt
 */
function yoast_description_as_excerpt( $excerpt ) {
    if ( ! is_admin() && has_excerpt() ) {
        return $excerpt;
    }

    $description = get_post_meta( get_the_ID(), '_yoast_wpseo_metadesc', true );

    if ( ! empty( $description ) ) {
        $excerpt = wp_strip_all_tags( $description );
        $excerpt .= '

‘ . apply_filters( ‘yoast_description_as_excerpt_more', __( ‘Read More', ‘your-text-domain' ) ) . ‘

‘; } return $excerpt; } add_filter( ‘get_the_excerpt', ‘yoast_description_as_excerpt' );

Customizing the “Read More” Button

Learn to add and customize the read more button in the GeneratePress Theme. Also, add a read more link if you are using a custom excerpt.

If you want to customize the Read More button then I have already written a tutorial about it.

At the End

By following the steps outlined in this tutorial, you can easily add meta descriptions as excerpt in GeneratePress theme, improving the user experience and potentially increasing your website’s search engine rankings.

If you have any questions or need further assistance, feel free to leave a comment below, and I’ll be happy to help!

Related articles

Seven Common WordPress Errors (and Simple Solutions)

Most of the people that read my blog have...

[Fix] Links Do Not Have a Discernible Name in WordPress

In this tutorial, we are going to fix issues...

How to Collapse Table of Contents in Rank Math?

In this tutorial, we are going to learn how...

How To Add Internal Links In WordPress Quickly

In my post about how I grew my organic traffic...

How to Add Phone Number and Email in GeneratePress Header?

In this tutorial, we’ll learn how to add phone...

Case Studies

Finance and Budgeting Blog

Easy Extra Dollar is your trusted source for valuable insights into finance, budgeting, and investing. The platform is dedicated to helping individuals and families...

Marketing Gamut – Marketing Blog

Marketing Gamut is the ultimate platform for marketing enthusiasts, offering valuable insights, engaging content, and thought-provoking discussions on all things marketing. The client needed...

Business and Marketing Insights Blog

Business Analysis is a platform dedicated to decoding the complexities of business and marketing through comprehensive data analysis and strategic planning. The client required...