waynedunkley
2/20/2015 - 4:19 AM

Wordpress Facebook Sharing V2

Wordpress Facebook Sharing V2

if (window.location.hash.indexOf('#close_window') > -1 ){
	window.close()
}
function mf_social_shares($id){

	$url = urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
	$fbid = urlencode( '1612208792340669' );
	$redirect_uri = urlencode("http://$_SERVER[HTTP_HOST]/#close_window");
	?>

	<a class="facebook" onClick="window.open('https://www.facebook.com/dialog/share?app_id=<?php echo $fbid;?>&display=popup&href=<?php echo $url;?>&redirect_uri=<?php echo $redirect_uri;?>','sharer','toolbar=0,status=0,width=648,height=325');" href="javascript: void(0)">
		<i class="icon-facebook"></i>
	</a>
			

	<?php
}
add_action('mf_social_shares', 'mf_social_shares', 1);

//Add the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
		return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
	}
add_filter('language_attributes', 'add_opengraph_doctype');

//Add Facebook Open Graph Meta Info
function insert_fb_in_head() {
	global $post;
	if ( is_singular()) //if this is a post or page
		$blog_title = get_bloginfo();
		$description = strip_tags( $post->post_content ); // Get Post content
        $description = str_replace('"', '\'', $description); // Replace all quotes
        if( strlen($description) > 300  ){ // Limit to 300 characters
        	$description = substr($description, 0, 300);
        };
        echo '<meta property="og:title" content="' . get_the_title( $id ) . '"/>';
        echo '<meta property="og:type" content="article"/>';
        echo '<meta property="og:url" content="' . get_permalink() . '"/>';
        echo '<meta property="og:site_name" content="' . $blog_title . '"/>';
        //var_dump( $post->post_content );
        echo '<meta property="og:description" content="'. $description .'"/>';
	if( has_post_thumbnail( $id ) ) {
		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
		$image = $image[0];
		echo '<meta property="og:image" content="' . $image . '"/>';
	}

	echo "";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
<?php do_action('mf_social_shares', $post->ID ); ?>