Replace default og:image tag YOAST

I'm trying to replace the default image picked by yoast (featured image) with a custom with the relative og:image:width and og:image:height, but seems a mission impossible!

I tryed with this:

function my_own_og_function() {
    $my_image_url = 'http://www.mywebsite.net/wp-content/uploads/TEST-A.jpg';
    $GLOBALS['wpseo_og']-image( $my_image_url ); // This will echo out the og tag in line with other WPSEO og tags
}
add_action( 'wpseo_opengraph', 'my_own_og_function', 29 );

But yes, the image is replaced, only is without og:image:width and og:image:height

So i'm wondering, is there away to make it possible? Please, i need your help to make this, i have spent all the night trying to achive what i'm looking for... Thanks a lot! :)

Topic plugin-wp-seo-yoast php plugins Wordpress

Category Web


Try this.

/* Yoast Seo Imagen Medium para compartir */
function sc_opengraph_image_size($size="medium") {
    return "medium";
}
add_filter('wpseo_opengraph_image_size','sc_opengraph_image_size',10,1);

Use the wpseo_opengraph_image_size filter. You can use any WP image size (default ones like medium or ones added by themes and plugins which will be specific to your site) in the first line:

// set 'medium' to whichever size you need
$size = 'medium';
// the size is then applied in this filter
add_filter('wpseo_opengraph_image_size', create_function("$size", 'return "opengraph";'));

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.