Support » Plugins and Hacks » Hacks » Get "Featured" or "Medium" post image for Facebook OG meta tag

  • Resolved xiabolai

    (@xiabolai)


    Hi,

    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?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    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.

    Hi!

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get "Featured" or "Medium" post image for Facebook OG meta tag’ is closed to new replies.