• Resolved oferlaor

    (@oferlaor)


    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)
  • Thread Starter oferlaor

    (@oferlaor)

    result for my URL (https://htmag.co.il/%d7%94%d7%92%d7%91%d7%a8-%d7%94%d7%9e%d7%95%d7%a9%d7%9c%d7%9d-%d7%a9%d7%9c%d7%9a.html) is:

    
    <meta property="og:image" content="https://htmag.co.il/thumb/Dan-Stevens_Sandra-Hu?ller_cChristine-Fenzl-copy-1614730501-568x320.jpg" class="yoast-seo-meta-tag" />
    <meta property="og:image:width" content="1296" class="yoast-seo-meta-tag" />
    <meta property="og:image:height" content="730" class="yoast-seo-meta-tag" />
    <meta property="og:image:type" content="image/webp" class="yoast-seo-meta-tag" />
    

    Hey @oferlaor,

    Thank you for reaching out.

    The question you specifically have is quite technical, and giving support on custom code or customization is outside of our support scope here, but if you can trace any issues or bugs towards our plugin and code, feel free to create a bug report in our GitHub repo where our development team and QA team is active to see if reported bugs/improvements can be investigated.

    Just while reading the issue, I have a feeling that the details of the previous image are still stored in our indexables table, if you’d try this where you are developing by resetting the indexables, check if that fixes our output. If not, the culprit must lay elsewhere.

    • This reply was modified 2 years, 1 month ago by Jeroen Rotty. Reason: add link to GitHub repo
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.