• Resolved porshegt9

    (@porshegt9)


    Hi

    I have a custom social share button on category pages.

    I implement it using functions.php but don’t know how to get og:image URL from category page. I need to get it for “media” of Pinterest share button URL:
    1) category image URL if it is manually added in?Social Media Preview Snippet for Facebook
    2) or if there is no such image, then use the global image URL from?Global Meta / OpenGraph Thumbnail


    <a href="https://pinterest.com/pin/create/button/?url=<?php echo $category_url; ?>&media=<?php echo $og_image_encoded; ?>&description=<?php echo $category_title_encoded; ?>"

    As, far as I understand I need to deal with rank_math/opengraph/facebook/og_image_secure_url or rank_math/opengraph/facebook/og_image but how to get it from category pages and what function to use I don’t understand.

    Thanks for help in advance!

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

    (@rankmathsupport)

    Hello @porshegt9,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    We usually use the filter hook rank_math/opengraph/facebook/og_image to retrieve and modify the OG image. You can proceed using that and store the value in any desired variable as it also retrieves the global image meta if there is no image explicitly added in the Social Media Preview Snippet.

    Or you can directly tap into the term meta:
    $og_image_encoded = get_term_meta(get_queried_object_id(), 'rank_math_facebook_image', true);

    For the retrieving the global value:
    if(empty($og_image_encoded)){
    $term = get_queried_object();
    $og_image_encoded = RankMath\Helper::get_settings( "titles.tax_{$term->taxonomy}_facebook_image_id" );
    }

    Let us know if this works for you.

    Looking forward to helping you.

    Thread Starter porshegt9

    (@porshegt9)

    Hello Rank Math Support

    Thank you for your answer.

    First code works, second – doesn’t. It doesn’t get the global value of og_image.

    Thread Starter porshegt9

    (@porshegt9)

    Figured out. Changed your code to this.

    Code that works:

         if(empty($og_image_encoded)){
    $og_image_encoded = RankMath\Helper::get_settings( "titles.open_graph_image" );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.