og:url and og:image

#176662
  • Resolved Victor Messner
    Rank Math free

    Hello, I’m trying to make og:url similar to og:image link, I’m using custom images as thumbnail for posts (using social snippet editor by Rank Math).
    I have tried with this and it works but it only shows the original thumbnail image as og:url

    function url ( $link ) {
    return get_the_post_thumbnail_url();
    }
    add_filter( ‘rank_math/opengraph/url’, ‘url’);

    I want to show the custom image, the one that is showing on og:image, so og:url will show same link as og:image

    I have tried this too but it’s not working

    function url ( $link ) {
    $img_url = $this->get_overlay_image( $this->prefix ) ? admin_url( “admin-ajax.php?action=rank_math_overlay_thumb&id={$image_meta[‘id’]}&type={$this->get_overlay_image( $this->prefix )}” ) : $image_url;
    return img_url;
    }
    add_filter( ‘rank_math/opengraph/url’, ‘url’);

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

    Hello,

    Thank you for getting back to us,

    You can use some of these filters to modify or change the og:url on your site/page: https://rankmath.com/kb/filters-hooks-api-developer/#change-opengraph-url

    There are other filters referenced on the same page to help you prevent the wrong og:image from being set or to change the og:image as well.

    Please note that you may need some help with a developer if you are not familiar with the filters here.

    However, if you need additional help please do let us know.

    We are looking forward to helping you.
    Thank you.

    Thank you for your reply but that’s not helping at all, I have already sent my own solutions that didn’t work which shows that I’m already familiar with https://rankmath.com/kb/filters-hooks-api-developer/#change-opengraph-url
    As I have mentioned in the post I just need og:url to show same link as og:image keeping in mind that I’m using custom image for social shares and not the post thumbnail.
    If anyone has a better code than this

    function url ( $link ) {
    return get_the_post_thumbnail_url();
    }
    add_filter( ‘rank_math/opengraph/url’, ‘url’);

    or help me make this one works, it will be really appreciated

    function url ( $link ) {
    $img_url = $this->get_overlay_image( $this->prefix ) ? admin_url( “admin-ajax.php?action=rank_math_overlay_thumb&id={$image_meta[‘id’]}&type={$this->get_overlay_image( $this->prefix )}” ) : $image_url;
    return img_url;
    }
    add_filter( ‘rank_math/opengraph/url’, ‘url’);
    Anonymous
    Rank Math free

    Hello,

    Thanks for getting back to us and we regret the inconvenience due to the issue.

    Here I am sharing a code that you need to put in your theme’s functions.php. It will add the og:image to the og:url

    add_filter( 'rank_math/opengraph/url', function ( $url ) {
    
    	if ( ! empty( $image_url = get_post_meta( get_the_ID(), 'rank_math_facebook_image', true ) ) ) {
    		return $image_url;
    	}
    
    	return $url;
    } );
    

    If you require any further assistance don’t hesitate to get in touch. Thanks

    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 ‘og:url and og:image’ is closed to new replies.