Snippet when sharing pages to social media

#63466
  • Resolved Kate
    Rank Math free

    Hi, when I share a page of my website to Facebook, it seems to use the short description field to produce a snippet, whereas for a google search, a default/automatic snippet comes from the main description field.
    As I am using the short description field to embed an audio clip on each product page, this means that the snippet actually shows a file path. Not a great look.
    How can I change this please? I have not been able to find it in the settings.
    An image is attached, for your information. Many thanks in anticipation of your assistance!

    https://ibb.co/VMrbvVK

    • This topic was modified 4 years, 5 months ago by Kate.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Todd
    Rank Math free

    Hi Kate,

    Thanks for getting in touch with us.

    You can choose the description you want to use from the social tab.

    Here is a screenshot for reference:

    Link to the screenshot: https://i.rankmath.com/Jl5rvR

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

    Kate
    Rank Math free

    Hi Todd, do you mean that I have to do this on every individual page/product?

    Hello,

    Thank you for contacting Rank Math today.

    That would be the way if you wish to have a different description for each page. The othe option would be to use this filter: https://rankmath.com/kb/filters-hooks-api-developer/#change-specific-social-meta, to modify the social share description for your pages.

    Hoping this helps you. Thank you.

    Kate
    Rank Math free

    I just want the snippet to be derived from the description field, rather than the short description field. Is there not a way to change that as a default?

    Alberto
    Rank Math business

    Hello,

    I did a simple snippet that you can add at the end of your functions.php file to display the Rank Math SEO Description (if any) instead of the Short Description on each of your posts:

    add_filter( "rank_math/opengraph/facebook/og_description", function( $shortDescription ) {
    	global $post;
    	$seo_description = get_post_meta( $post->ID, 'rank_math_description', true );
    	return $seo_description ? $seo_description : $shortDescription;
    });

    Looking forward to help you.

    Kate
    Rank Math free

    These seem to now work for some products but not others. Any idea why this would be? Some products are still grabbing the audio filepath from the short description field. Any ideas how to fix?

    Thank you for your help.

    Kate
    Rank Math free

    Can you create a snippet to make it take information from the product description field, instead of the short description field, in the case where the seo description is blank? This is what I need.

    Hello,

    You can try using the following filter

    add_filter( "rank_math/opengraph/facebook/og_description", function(shortDescription) {
    	global $product;
    	$seo_description = $product->get_description();
    	return $seo_description ? $seo_description : $shortDescription;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Kate
    Rank Math free

    Hi, are you sure this code is correct? I get an error when I try to add it.

    Hello,

    Let me check with the dev team and will let you know.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Please add following filter code in your theme’s functions.php to use Product’s main content in the description:

    
    add_filter( 'rank_math/frontend/description', function( $desc ) {
    	if ( ! function_exists( 'is_product' ) || ! is_product() ) {
    		return $desc;
    	}
    
    	global $post;
    
    	return wp_trim_words( $post->post_content, 160 );
    } );
    

    I 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 11 replies - 1 through 11 (of 11 total)

The ticket ‘Snippet when sharing pages to social media’ is closed to new replies.