WordPress Yoast SEO Plugin and opengraph tags

I have a wordpress page that is dynamic. WordPress SEO By Yoast adds opengraph tags to all pages which isn’t a problem except on this one page.

Is there a way to overwrite the meta tags with more dynamic content?

Related posts

Leave a Reply

2 comments

  1. Looking through the code of Yoast SEO, I found many “undocumented” filters you can use. Here is a list extracted from it:

    wpseo_opengraph_author_facebook – Allow developers to filter the
    Yoast SEO post authors facebook profile URL
    wpseo_opengraph_admin – Allow developer to filter the fb:admins
    string put out by Yoast SEO wpseo_opengraph_title – Allow changing
    the title specifically for OpenGraph
    wpseo_opengraph_url – Allow
    changing the OpenGraph URL wpseo_opengraph_type – Allow changing the
    OpenGraph type of the page
    wpseo_opengraph_desc – Allow changing
    the OpenGraph description
    wpseo_opengraph_site_name – Allow
    changing the OpenGraph site name wpseo_opengraph_show_publish_date
    Allow showing publication date for other post types
    wpseo_opengraph_image_size – Allow changing the image size used for
    OpenGraph sharing wpseo_opengraph_image – Allow changing the
    OpenGraph image.
    wpseo_twitter_card_type – Allow changing the
    Twitter Card type as output in the Twitter card by Yoast SEO
    wpseo_twitter_metatag_key – Make the Twitter metatag key
    filterable
    wpseo_twitter_description – Allow changing the
    Twitter description as output in the Twitter card by Yoast SEO
    wpseo_twitter_title – Allow changing the Twitter title as output in
    the Twitter card by Yoast SEO wpseo_twitter_site – Allow changing
    the Twitter site account as output in the Twitter card by Yoast
    SEO
    wpseo_twitter_image – Allow changing the Twitter Card
    image
    wpseo_twitter_image_size – Allow changing the Twitter Card
    image size wpseo_twitter_creator_account – Allow changing the
    Twitter account as output in the Twitter card by Yoast SEO

    EDIT:
    A few things to remember:
    Facebook scraps the url in the og:url tag (even if it’s not the actual url you give it).
    If you return false from the wp filter function, Yoast will not display that tag, so you can use it like that, and then manually add the tag somewhere else in your code where you need…

    For example, here is some code to disable description and image tags for og and twitter:

     function yoast_og_tag ($tag) {
        return false;
     }
     $yfilters = [ 'wpseo_opengraph_desc','wpseo_opengraph_image','wpseo_twitter_description','wpseo_twitter_image' ];
     foreach ($yfilters as $k => $f) {
          add_filter( $f, 'yoast_og_tag', 10, 1 );
     }
    
  2. Yoast make various filters available. See their WordPress SEO API Docs article for a list of them. So, for example, if you wanted to change the opengraph type of a blog post with ID 86, you could use the wpseo_opengraph_type filter:

    function modify_opengraph_type_p86( $type ) {
        if ( is_single( 86 ) )
            $type = 'video';
    
        return $type;
    }
    add_filter( 'wpseo_opengraph_type', 'modify_opengraph_type_p86' );