1

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! :)

0

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";'));
  • But in wordpress settings i have set all thumb size to "0", because i don't want any cropped image... In your way can i set manually width and height? Or even with getimagesize() ? – ChristianWeb Jun 5 '18 at 19:48
  • <b>Deprecated</b>: Function create_function() is deprecated in... – ChristianWeb Jun 5 '18 at 20:06
0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.