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

wordpress.stackexchange https://wordpress.stackexchange.com/questions/99178

  •  05-11-2019
  •  | 
  •  

Question

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);
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top