I´m running a website using Yoast SEO and from unknown reasons the images of my posts are not shown if I share the links on social media. I found the following post which recommends to replace "og:image" by "og:image:secure_url", since the image is located on an https url.
how to fix facebook open graph images...
So I added the following code to my functions.php file:
(I deleted some lines which create an additional metatag for og:image with an http url since I do not need that.)
function check_ssl_facebook_opengraph_image($image) {
$og = "og:image";
if (preg_match('/^https/', $image)) {
echo '<meta property="'. $og . ':secure_url" content="'. $image . '" />' . "\n";
}
}
// Hook into the Yoast plugin's hooks for handling the OG image
add_action('wpseo_opengraph_image', 'check_ssl_facebook_opengraph_image');
Unfortuntaly the code doesn´t replace the line in my wp-theme but adds a new line. As a result the post does include og:image and og:image:secure_url metatags with the same url.
I want to delete og:image from my post now since the image is still not visible if I post the link to social media. Perhaps it will be visible if only og:image:secure_url is present in my post.
I´m an absolute beginner with php. Can someone tell me how to delete the unneccessary og:image metatag after the secure_url string has been added?
Thanks in advance Marc
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand