How to use the Rankmath meta description as the excerpt on all my posts and page

#662587
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to this issue.

    By default, without making changes Rank Math uses the excerpt which is the first 55 words of your post content (post_content) as the meta description. WordPress already generates this variable(%excerpt%) that the Rank Math meta description pulls from by default.

    However, some themes or builder plugins don’t save data inside that field. Therefore we cannot generate the description from that variable.

    What you can try is to add your text in the custom excerpt field.

    We hope this helps. Please let us know if you have further questions or concerns.

    Thank you.

    Thanks, but I don’t think this addresses my needs. I was asking how can I adjust the code so that pages that don’t have an excerpt (which is currently the majority of my pages) get given the current Rankmath meta description as the excerpt. Another way to put it would be how do I overwrite the excerpt for all pages using the Rankmath meta description as the text?

    Hello,

    Please note that there is no built-in way to automatically copy the meta description of Rank Math to excerpt fields in WordPress.

    However, you can use a custom PHP code or a plugin to achieve this. For example, you can create a Custom Plugin with this code:

    <?php
    /*
        Plugin Name: Rank Math Meta Description to Excerpt
        Plugin URI: https://support.rankmath.com/ticket/copy-meta-description-to-subtitle-and-excerpt-2/
        Description: Custom Plugin to copy Rank Math Meta Description to Excerpt
        Author: Rank Math Support
    
    */
    register_activation_hook( __FILE__, 'rm_to_excerpt' );
    
    function rm_to_excerpt()
    {   
        $args = array( 
            'post_type'   => 'post'
        ,   'numberposts' => -1
        );
        $posts = get_posts( $args );
        foreach ( $posts as $post )
        {
            if( '' == $post->post_excerpt )
            {
                $rm = get_post_meta( $post->ID, 'rank_math_description' ,true);
                if( '' != $rm )
                {
                    $po = array();
                    $po = get_post( $post->ID, 'ARRAY_A' );
                    $po['post_excerpt'] = $rm;
                    wp_update_post($po);
                }
            }
        }   
    }

    To create a folder in /wp-content/plugins and add the above code to a PHP file in the folder, then visit your WordPress dashboard to activate the plugin.

    This custom plugin code would iterate through your post and update every post without an excerpt with the post’s Rank Math meta description.

    Hope that helps.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to use the Rankmath meta description as the excerpt on all my posts and page’ is closed to new replies.