Open graph metadata isn’t pulled on Facebook until after I run that specific link through the debugger

I added open graph meta data to all the posts on a site, however, when I attempt to paste a post link on Facebook, the graph meta information isn’t loaded.

Then, when I insert the URL into the debugger / linter, it works, both within the debugger and when posting normally on Facebook (which didn’t work moments prior).

Read More

This issue seems to have been addressed in the past, in this Stack Overflow question. However that question pertains to a Rails environment.

In that question, the application couldn’t handle multiple http requests at the same time. The issue was solved by handling all Facebook API requests in the background using something called delayed_response.

What’s the simplest fashion in which I could accomplish this or something similar in a PHP environment running WordPress and thereby (hopefully) solve my problem?

**I didn’t include a sample link in this post because as soon as a user runs it through the debugger, it’ll appear to work.*

Edit- Sample of meta tags from a post page:

<meta property="og:title" content="Budget proposal good news for Ontario drivers - AdvocateDaily.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://build.advocatedaily.com/wp-content/uploads/2013/04/Stacey-Stevens_Colour_NEW_2012-e1354206636925-150x150.jpg" />
<meta property="og:url" content="http://advocatedaily.com/2013/05/budget-proposal-good-news-for-ontario-drivers/" />
<meta property="og:description" content="A provincial budget proposal to reduce auto insurance premiums by an average of 15 per cent is good news for Ontario drivers, but should not come at the cost of benefits available under the policy, says Toronto personal injury lawyer Stacey L. Stevens. “In response to this announcement, the Insurance Bureau of Canada (IBC) predicts the [...]" />
<meta property="og:site_name" content="Advocate Daily" />

The PHP being inserted into wp_head:

add_action('wp_head', 'add_fb_open_graph_tags');
function add_fb_open_graph_tags() {
    if (is_single()) {
        global $post;
        if(get_the_post_thumbnail($post->ID, 'thumbnail')) {
            $thumbnail_id = get_post_thumbnail_id($post->ID);
            $thumbnail_object = get_post($thumbnail_id);
            $image = $thumbnail_object->guid;
        } else {
            $image = get_template_directory_uri()."/images/advocatedaily-avatar.png";
        }
        //$description = get_bloginfo('description');
        $description = og_excerpt( $post->post_content, $post->post_excerpt );
        $description = strip_tags($description);
        $description = str_replace(""", "'", $description);
?>
<meta property="og:title" content="<?php the_title(); ?> - AdvocateDaily.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="<?php echo $image; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:description" content="<?php echo $description ?>" />
<meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>" />
<?php   }
}
function og_excerpt($text, $excerpt){
    if ($excerpt) return $excerpt;
    $text = strip_shortcodes( $text );
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = strip_tags($text);
    $excerpt_length = apply_filters('excerpt_length', 55);
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    $words = preg_split("/[n
     ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if ( count($words) > $excerpt_length ) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . $excerpt_more;
    } else {
            $text = implode(' ', $words);
    }
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}

Related posts

2 comments

  1. First, this isn’t a WordPress specific question, it’s a Facebook question.

    Secondly, Facebook caches pages, they don’t crawl them on every submission. If you have a URL that has already been submitted to Facebook before, then they will have already crawled it for the OG data once before, and saved it to their cache. If you later change the OG data, they won’t notice it immediately, because they’re pulling from their cache, not from the page.

    The Facebook Debugger forces their crawler to pull from the page in real-time, and thus updates their cache.

    Simple as that really. If the URL has ever been posted to Facebook before, then changing the OG data on it won’t take immediate effect. It’ll take a few weeks before FB notices. Using the debugger overrides that.

  2. I had the same problem. What you need to is to tell Facebook to scrape your content again.

    Head over to this link: https://developers.facebook.com/tools/debug/sharing/ and plug your URL in. After the debugger comes back, you should see a button that says “scrape again”. Click it.

    After I did that, the information appeared as normal on Facebook.

    I’m sure there’s a more direct way to tell Facebook to scrape your content anew but this works, too.

Comments are closed.