creating a custom og:image url – how to adjust other properties
-
I have been playing around with the option of creating an automatic migrator from webp to jpg for the og:image meta tag. Problem is, that the og:image properties (like width, height and type) don’t adjust or even reset when you adjust the URL. Seems like this is a bug in yoast, where if you override the URL, it should disregard these from the original image, but it doesnt.
Here is my code snippet:
add_filter('wpseo_opengraph_image', 'fix_image', 10, 2); function fix_image($image, $present) { if( is_single()) { DoLog(var_export($image, true)); $thumb= get_the_post_thumbnail_url(get_the_ID(), 'mobile'); $thumbext= substr($thumb, -4); switch ($thumbext) { case '.png': case '.jpg': break; case 'webp': preg_match('/^((?:http|https)(?::\/\/)(?:.*?))((\/(?:.*?\/)*)((.*)(\..*)))$/i', $thumb,$match); $src= getcwd() . $match[2]; $dir= '/thumb/'; $ext= ".jpg"; $thumb= $match[1] . $dir . $match[5] . $ext; $tgt= getcwd() . $dir . $match[5] . $ext; if (!file_exists($tgt)) { $im = imagecreatefromwebp($src); imagejpeg($im,$tgt, 100); imagedestroy($im); } break; } return $thumb; } return $image; }
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘creating a custom og:image url – how to adjust other properties’ is closed to new replies.