[resolved] Get "Featured" or "Medium" post image for Facebook OG meta tag (3 posts)

  1. xiabolai
    Posted 3 years ago #


    I'm using the following to get the post thumbnail for the Facebook OG meta tags:

    <meta property="og:image" content="<?php if (function_exists('wp_get_attachment_thumb_url')) {echo wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID)); }?>" />

    The problem is my thumbnails are 150 x 150 and Facebook requires minimum size of 200 x 200. So, instead of rebuilding and changing all thumbnail sizes, I want to modify the code above to grab either the "Medium" image or the "Featured" image. I've tried a lot of things but nothing works.

    Anyone have any ideas?


  2. bcworkz
    Posted 3 years ago #

    You could try getting the image url like so:
    wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
    I'm assuming get_post_thumbnail_id() actually returns the attachment id that wp_get_attachment_image_src() needs. You'll want to test to ensure this.

  3. xiabolai
    Posted 3 years ago #


    Yes, that worked! Was driving me crazy...thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic