neděle 3. května 2015

Update Facebook Sharer Cache automatically on Page Load

So I have this problem on my one of my clients website. The Facebook cache was not updateed correctly. And no images was loaded. I know that in every 24 hour the cache is updated. But I need this to be done automatically on page load now. This solution is good for WordPress and WooCommerce too. Add this to your functions.php file and the Sharer Cache will be updated on page load.
add_action( 'wp_footer', 'fb_sharer_updater', 5 );

if(!function_exists('fb_sharer_updater')) {
    function fb_sharer_updater() {
        global $post;
            
            echo '<script type="text/javascript">
    jQuery.post(
    "https://graph.facebook.com",
    {
     id: "'.  get_permalink() .'",
     scrape: true
    },
    function(response){
     console.log(response);
    }
   );';
            echo '</script>';
            
        
    }
}
You need to wait approx 5seconds, then the new scrape info is added to FB cache. Open Developer Console and you will see additional information:
Object {url: "http://theblackcat.sk/produkt/plazove-saty-texas-s-5995/", type: "article", title: "Plážové šaty Texas S-5995 - TheBlackCat.sk", locale: Object, image: Array[1]…}
description: "Ľahučké plážové šaty so vzorom, s viazaním na boku. Plážové šaty odporúčame ku všetkým bikinám Texas 2015 ako doplnka."
id: "1532012490185775"
image: Array[1]
locale: Object
site_name: "TheBlackCat.sk"
title: "Plážové šaty Texas S-5995 - TheBlackCat.sk"
type: "article"
updated_time: "2015-05-03T14:23:15+0000"
url: "http://theblackcat.sk/produkt/plazove-saty-texas-s-5995/"
__proto__: Object

Žádné komentáře:

Okomentovat