Force og:image from custom field

#761259
Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    I apologize for the inconvenience you’ve faced with the Open Graph image not displaying correctly on your website. To force the og:image from custom fields like field_category_photo and field_camp_category_photo, you can use the following filters in Rank Math:

    1. For field_category_photo:

      add_filter( 'rank_math/opengraph/image', function( $image ) {
       $custom_image = get_post_meta( get_the_ID(), 'field_category_photo', true );
       if ( ! empty( $custom_image ) ) {
           return $custom_image;
       }
       return $image;
      });
    2. For field_camp_category_photo:

      add_filter( 'rank_math/opengraph/image', function( $image ) {
       $custom_image = get_post_meta( get_the_ID(), 'field_camp_category_photo', true );
       if ( ! empty( $custom_image ) ) {
           return $custom_image;
       }
       return $image;
      });

    You can add these filters using the Code Snippets plugin or directly to your theme’s functions.php file.

    After adding these filters, please check the sample pages you provided:

    If you encounter any issues or need further assistance, please feel free to reach out to us. Thank you for bringing this to our attention, and we appreciate your patience.

    Sources:
    How to Fix the ‘og: image’ Property Should Be Explicitly Provided » Rank Math
    Open Graph Meta Tags » Rank Math
    Open Graph/Social Preview Image Is Not Displayed » Rank Math
    How to Configure Sitemaps in Rank Math – Best Settings and Tips
    Rank Math SEO Filters and Hooks for Developers – Rank Math

    Hello,

    Thank you for contacting Rank Math support.

    You can modify and use the following filter to update the OG image: https://rankmath.com/kb/filters-hooks-api-developer/#change-opengraph-image

    I checked your site, and those custom fields are not being saved in the database, so we won’t be able to fetch the image URL from them. You will have to share the filter with the developers of the plugin that you are using to create those post types and ask them to help you modify it to use the images you are selecting for those fields.

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

    Ok, I will do that, unfortunately their response time is very slow.

    If it matters – I am setting the Open Graph Image using the RankMath Box where you can “Here you can view and edit the thumbnail, title and description that will be displayed when your site is shared on social media.”

    So I don’t need it to pull the custom taxonomy photo, I just need it to use the photo I select via RankMath. This works on regular pages/posts (it shows the image I select using the RankMath box) but does not work on custom taxonomies like directory categories.

    I did not have this issue when I used Yoast, which leads me to believe there is a conflict or my settings are being overridden somewhere, I’m just not a developer to be able to troubleshoot this. If you have any other suggestions, I’m happy to try them.

    I have 300 directory categories / website pages where this is an issue – if I try to share any of them on social, it shows a generic website image instead of the assigned photo. Unfortunately if I can’t get this resolved I’ll have to switch back to Yoast which would make me very sad, I like RankMath much better.

    To make this even more complicated… (or maybe not?)
    When I switch themes to Twenty Twenty Two, the og:image is the correct image.
    My current theme is Astra Pro.
    Any other suggestions for troubleshooting this?
    Again, the og:image is correct for posts and pages, but not custom taxonomies or directory listings generated by my Directories Pro plugin.

    Hello,

    With Rank Math, it is possible to change the social details of a custom taxonomy. Please head over to your WordPress Dashboard > Rank Math > Titles & Meta > [find the custom taxonomy] and enable the “Add SEO Controls” option:

    Rank Math support

    Once enabled, you should be able to see the Social tab in the custom taxonomy like you how you do it on regular posts and pages.

    Looking forward to helping you.

    That setting has been turned on since the day I started using Rank Math. I’m able to set the social share image and other meta settings using Rank Math on those custom taxonomy pages. The issue is that for some reason they aren’t showing any og:image at all even when I have set it using the RankMath box and social tab.

    Hello,

    Could you possibly re-enable the login link so we can check the taxonomies and the OpenGraph generation to pinpoint exactly what the issue is?

    Looking forward to hearing back from you.

    Yes – I have re-enabled the login link, unfortunately I’m only able to do 24 hours at a time. Hopefully that is long enough, if not let me know.

    Hello,

    Thank you for your patience.

    The login link is only redirecting to your homepage.

    Please extend the validity to at least 3 days so our team can investigate the issue.

    Looking forward to helping 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 9 replies - 1 through 9 (of 9 total)

The ticket ‘Force og:image from custom field’ is closed to new replies.