How to exclude text from meta description

#41458
  • Resolved Randi Thornton
    Rank Math free

    Hi!

    A YouTube video gets added to the top of every post and the text content follows. I am using %excerpt% for the meta description.

    Here is the result:
    <meta name=”description” content=”https://www.youtube.com/watch?v=Tx7EbQ_ABCC”/&gt;

    How do I eliminate the YouTube video link from appearing in the meta description and have the text that follows be used instead?

    Thank you in advance for your help and support!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Todd
    Rank Math free

    Hi Randi,

    Thanks for getting in touch with us.

    When you choose the %excerpt% for meta description, we grab whatever is present in the first paragraph of your page. In this case, it seems like that’s the YouTube URL.

    You can get around this by using a custom meta description for pages like these.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hi!

    Thanks for your quick response. What you are referring to when you say add a custom meta description? Manually adding meta descriptions isn’t an option. I need a way to insert meta descriptions automatically with text below the video. Please advise. Thanks again for your help and support and I look forward to hearing from you.

    Hello,

    Thank you for contacting Rank Math today.

    You can workaround this limitation by adding the following code snippet on your theme’s functions.php file:

    /**
     * Allow changing the meta description sentence from within the theme.
     *
     * @param string $description The description sentence.
     */
    add_filter( 'rank_math/frontend/description', function( $description ) {
    	
    	return preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $description);
    	
    });

    Please note that this will only change the description on the frontend and not the on the backend Rank Math metabox.

    Looking forward to helping you. Thank you.

    ​​​​​​

    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 exclude text from meta description’ is closed to new replies.