• Well this is quite specific, so please let me know if it helps with a screencast.

    Really awesome that RM supports Custom Post Types!

    In the SEO Titles & Meta > {CPT name} > Single {CPT name} Description, I might put something like %customfield(field-name)% – and it would work just fine, and the Meta Description tag would be whatever chosen field name, just like I need it to.

    Unless! the post has an Excerpt (necessary for other reasons), cause in that case, RM outputs the Excerpt as Meta Description, regardless of my global setting. I don’t think that is ideal, as 1) I can just use the %excerpt% tag in my Single {CPT name} Description setting if I want to use the excerpt field as Meta Description and 2) its possible to overrule the Meta Description on a post by post basis if needed.

    So – to recap. I need the option to set a global Meta Description that pulls data from a custom field, while having an Excerpt field on the post that is NOT used for Meta Description. All this seems almost possible in RM today, except that RM always uses Post Excerpt for meta description if set.

    Does that make sense?

    RM is the closest thing I’ve seen to a SEO plugin fully supporting Custom Post Types. I’d love to overcome this little hurdle.

    Kind Regards
    Bjarne

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rank Math SEO

    (@rankmath)

    Hello @oldrup,

    Thank you for contacting Rank Math.

    Below is the sequence which Rank Math uses to generate the description:

    1) The Description text added in the Description field of single Post/Page
    2) If text is not added in the Description field then the plugin will use excerpt/short description
    3) If the short description field is also empty then plugin will use the value added in the Global Settings.

    If you want Rank Math to use the value from step 3 instead of 2, then please add below filter code in your theme’s functions.php file:

    add_action( 'rank_math/frontend/description', function( $description ) {
        global $post;
        $desc = RankMath\Post::get_meta( 'description', $post->ID );
    
        if ( ! $desc ) {
            $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
            if ( $desc ) {
                return RankMath\Helper::replace_vars( $desc, $post );
            }
        }
    
        return $description;
    });

    Hope this helps.

    Thank you.

    Thread Starter Bjarne Oldrup

    (@oldrup)

    Awesome! That Works!

    Using the also amazing plugin “Code Snippets” I added the code without messing with functions.php.

    1) Using %customfield(fieldname)% now returns content of ‘fieldname’ as meta description, regardless of any excerpt.
    2) Using %excerpt% returns the post excerpt as meta description if needed.
    3) Entering a specific description on the individual post, still has priority over the global setting

    IMO that behaviour is preferable and I’d be happy to see that as an option. After all, %excerpt% could be the default global option, and the experience would be the same to anyone not juggling with advanced settings. Or maybe I’m missing something?

    The snippet is an acceptable solution though – and thank you for replying so fast!

    Bjarne

    Plugin Author Rank Math SEO

    (@rankmath)

    Hi @oldrup,

    Glad to know that.

    Yes, we are aware of this behaviour and our developers are working on it, in one of the upcoming updates we will introduce the new filter, which can help you to change the priority.

    Hope this helps.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CPT excerpt overrules global meta description’ is closed to new replies.