twitter:image and og:image with ACF

#569925
  • Resolved Anonymous
    Rank Math free

    Hello
    I have website for a client that have ACF, and I installed Rank MATH, I want the feature image for custom fields to be picked up automatically for twitter:image and og:image.
    the problem is that the rank math picked the fallback thumbnail.
    when I set the field for the OG image to return the image URL, it does not working, also the image broken on the page itself.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.

    You can implement this with our plugin with the help of the following filter: https://rankmath.com/kb/filters-hooks-api-developer/#change-opengraph-image

    For example, let’s say you have a field called og-image in ACF and you want to set that as the OpenGraph image, the following code should achieve that:

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
        $new_image_url = get_field('og-image');
        if($new_image_url){
            $attachment_url = $new_image_url;
        }
        return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
        $new_image_url = get_field('og-image');
        if($new_image_url){
            $attachment_url = $new_image_url;
        }
        return $attachment_url;
    });
    

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. 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 1 replies (of 1 total)

The ticket ‘twitter:image and og:image with ACF’ is closed to new replies.