yoast creates multiple og image tags, how to only use the one i defined?

I am having an issue with the SEO plugin from Yoast. By default, the Yoast plugin for WordPress creates multiple og:image tags on my site. But I have no idea how to remove the other ones that are being generated by the plugin…

So how do i force it to only use the one I defined in the social section of the plugins settings area?

Read More

Best Regards

Related posts

Leave a Reply

2 comments

  1. Webzunft’s answer worked okay for me in removing the extra images but it broke the Keyword Density and other counts in Page Analysis tab. I solved it by stripping img tags from the content instead of returning an empty string:

    function mysite_opengraph_content($val) {
        return preg_replace("/<img[^>]+>/i", "", $val); 
     }
    add_filter('wpseo_pre_analysis_post_content', 'mysite_opengraph_content');
    

    This way the plugin sees the text with no images and counts keywords correctly.

  2. WordPress SEO creates the Open Graph tags for images for the featured image, all the images from the post content and if not any of those, uses the default image you specified in the settings area.

    In my case, I wanted to switch off the use of the images in the content and only create the Open Graph tag for the featured image. This is easy added the following filter in your theme’s functions.php:

    add_filter('wpseo_pre_analysis_post_content', 'mysite_opengraph_content');
    function mysite_opengraph_content($val) {
        return '';
    }
    

    This clears the content that is searched for images.

    I explained the 3 filters one might use to manipulate how WordPress SEO created the Open Graph for images in this article: http://webgilde.com/en/wordpress-seo-facebook-image-open-graph/

    UPDATE: as JoseV pointed out, my function has a drawback. The filter is also used when analyzing the content for SEO. JoseV posted a solution that prevents some of the analysis functionalities.