Skip to content

Instantly share code, notes, and snippets.

@frnwtr
Last active January 3, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frnwtr/8383808 to your computer and use it in GitHub Desktop.
Save frnwtr/8383808 to your computer and use it in GitHub Desktop.
Auto update Facebook OG cache on Wordpress post save
<?php
function facebook_cache_update( $post_id ) {
// If this is just a revision, don't update
if ( wp_is_post_revision( $post_id ) )
return;
$url="https://graph.facebook.com/";
$post_url = get_permalink( $post_id );
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array( 'id' => $post_url, 'scrape' => 'true' ),
'cookies' => array()
)
);
}
add_action( 'save_post', 'facebook_cache_update' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment