Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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).

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. &#8220;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);
}
share|improve this question
    
How had you added it and what precisely you are doing to proactively notify Facebok about it? –  Rarst May 12 '13 at 13:38
    
I have a function that writes to my header if is_post(). I'll edit my post and add a sample snippet of the metadata. –  Orun Bhuiyan May 12 '13 at 14:52
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
1  
Thanks, I'll wait it out. I posted this question in Wordpress because I was wondering if there was a best way to handle Facebook API requests in the background in a Wordpress environment, that being said, your point is totally fair and your answer makes sense. Thanks. –  Orun Bhuiyan May 13 '13 at 2:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.