I have code in my page header which properly creates the Open Graph tags for pages, posts, etc. However, when I attempt to Share an attachment post from the Media Library (not the actual attachment image, but rather the URI), the FB Object Debugger complains

  "Error parsing input URL, no data was cached, or no data was scraped."

I've examined the header on generated pages and they appear identical to other Pages, Posts and other Custom Post types. We were using Yoast and I -thought- that this was the problem, but I disabled it and still not working.

Eg. the WordPress URL is


Which contains a link to:


Which works fine.

Here is the code I put in my header. Which (again) works FINE for all other post types. But not attachments.

function insert_fb_in_head() {

    $og_title = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true);
    if( ! $og_title)    
        $og_title = get_the_title();

    echo ('<meta property="og:title" content="' . $og_title . '"/>' . PHP_EOL);
    echo ('<meta property="og:type" content="article"/>' . PHP_EOL);
    echo ('<meta property="og:url" content="' . get_permalink() . '"/>' . PHP_EOL);
    echo ('<meta property="og:site_name" content="Noise Information"/>' . PHP_EOL);
    echo ('<meta property="og:description" content="' . strip_tags( get_post_meta( get_the_ID(), '_yoast_wpseo_metadesc', true), '' ) . '"/>' . PHP_EOL);

    if( has_post_thumbnail( $post->ID )) { //the post has a featured image, use a default image
        $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
        echo ('<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>' . PHP_EOL);
        echo ('<meta property="og:image:width" content="' . esc_attr( $thumbnail_src[1] ) . '"/>' . PHP_EOL);
        echo ('<meta property="og:image:height" content="' . esc_attr( $thumbnail_src[2] ) . '"/>' . PHP_EOL);      

    echo ('<meta property="og:image" content="' . $default_image . '"/>' . PHP_EOL);
    echo ('<meta property="og:image:width" content="250"/>' . PHP_EOL);
    echo ('<meta property="og:image:height" content="250"/>' . PHP_EOL);        
 add_action( 'wp_head', 'insert_fb_in_head', 5 );

Here is the section of an example rendered page source HTML:

  <meta property="og:title" content="2017 POS CAFR FINAL 5.2.2018"/>
  <meta property="og:type" content="article"/>
  <meta property="og:url" content="http://example.com/2017-pos-cafr-final-5-2-2018-2/"/>
  <meta property="og:site_name" content="Example Site"/>
  <meta property="og:description" content="2017 POS CAFR FINAL 5.2.2018"/>
  <meta property="og:image" content="http://example.com/wp-content/uploads/airplane-large-circles-stretched-250.png"/>
  <meta property="og:image:width" content="250"/>
  <meta property="og:image:height" content="250"/>

AGAIN, I asked this question in another thread and it was suggested to try using Yoast and changing the setting in the "Redirect attachment URLs to the attachment itself?" But that made no difference and in fact, de-activating Yoast entirely made no difference.


  • If you're redirecting to a PDF file how is Facebook supposed to scrape that? PDFs aren't HTML documents, so they're not going to have any meta tags and wp_head() isn't output for the files themselves. – Jacob Peattie Jan 31 at 3:37
  • I'm -not- redirecting to a PDF. I'm displaying the Wordpress attachment page which is a wordpress post with a link to the PDF. – jchwebdev Jan 31 at 7:54
  • Why did you say "Which properly redirects (301) to" about a .pdf file then? – Jacob Peattie Jan 31 at 8:00
  • Deepest apologies. I made the unforgivable mistake of copy/pasting a similar (but not identical) issue. Question edited. The problem remains. Posts of type "attachment" are not being 'captured' by the Facebook Object Debugger even though the source html appears identical to other posts. Why? – jchwebdev Jan 31 at 18:21
  • If you're redirecting visitors to your attachment page to the actual file, then won't facebook also follow that redirect? A good chunk of this question requires Facebook specific domain knowledge that has nothing to do with WordPress, you'll need to narrow this down further than "it doesn't work" – Tom J Nowell Jan 31 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.