<?php
if( !function_exists( ‘add_opengraph_doctype’ )):
////////////////////////////////////////////////////////////////////
//Adding 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’);
endif;
if( !function_exists( ‘insert_fbog_in_head’ )):
/////////////////////////////////////////////////////////////////////
//Adding and insert Facebook Open Graph in wp_head()
/////////////////////////////////////////////////////////////////////
function insert_fbog_in_head() {
global $post, $aioseop_options;
/* Get thumbnail for Facebook Open Graph */
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), “thumbnail” );
$fb_app_id = ”; /* app id فیسبوک شما */
$fb_user_id = ”; /* id فیسبوک شما */
?>
<!— start FB OPEN GRAPH code —>
<?php if($fb_app_id): ?><meta property=“fb:app_id” content=“<?php echo $fb_app_id; ?>“ /><?php endif; ?>
<?php if($fb_user_id): ?><meta property=“fb:admins” content=“<?php echo $fb_user_id; ?>“ /><?php endif; ?>
<?php if( is_singular() ) { ?>
<!— if currently in single post or page —>
<meta property=“og:url” content=“<?php echo the_permalink() ?>“/>
<!— using title from aioseo wp plugin —>
<?php if ( function_exists(‘aioseop_load_modules’)) {
$post_aioseo_title = get_post_meta($post->ID, ‘_aioseop_title’, true);
if($post_aioseo_title): ?>
<meta property=“og:title” content=“<?php echo $post_aioseo_title; ?>“ />
<?php else: ?>
<meta property=“og:title” content=“<?php echo get_the_title(); ?>“ />
<?php endif; ?>
<?php } else { ?>
<meta property=“og:title” content=“<?php echo get_the_title(); ?>“ />
<?php } ?>
<!— using description from aioseo wp plugin —>
<?php if ( function_exists(‘aioseop_load_modules’)) {
$post_aioseo_desc = get_post_meta($post->ID, ‘_aioseop_description’, true);
if($post_aioseo_desc): ?>
<meta property=“og:description” content=“<?php echo stripcslashes($post_aioseo_desc); ?>“ />
<?php else: ?>
<meta property=“og:description” content=“<?php echo the_excerpt(); ?>“ />
<?php endif; ?>
<?php } else { ?>
<meta property=“og:description” content=“<?php echo the_excerpt(); ?>“ />
<?php } ?>
<meta property=“og:type” content=“article” />
<!— use default image if thumbnail not found —>
<meta property=“og:image” content=“<?php if( !empty($thumbnail_src) ) { echo $thumbnail_src[0]; } elseif ( file_exists( get_template_directory() . ‘/noimage.png’ ) ) { echo get_template_directory_uri() . ‘/noimage.png’; } ?>“ />
<meta property=“og:site_name” content=“<?php bloginfo(‘name’); ?>“ />
<?php } else { ?>
<!— if currently in homepage —>
<meta property=“og:site_name” content=“<?php bloginfo(‘name’); ?>“ />
<!— using home title from aioseo wp plugin —>
<?php if ( function_exists(‘aioseop_load_modules’)) {
$hometitle = $aioseop_options[‘aiosp_home_title’];
if($hometitle): ?>
<meta property=“og:title” content=“<?php echo $hometitle; ?>“ />
<?php else: ?>
<meta property=“og:title” content=“<?php bloginfo(‘description’); ?>“ />
<?php endif; ?>
<?php } else { ?>
<meta property=“og:title” content=“<?php bloginfo(‘description’); ?>“ />
<?php } ?>
<meta property=“og:url” content=“<?php echo site_url() ?>“/>
<!— using home description from aioseo wp plugin —>
<?php if ( function_exists(‘aioseop_load_modules’)) {
$homedesc = $aioseop_options[‘aiosp_home_description’];
if($homedesc): ?>
<meta property=“og:description” content=“<?php echo $homedesc; ?>“ />
<?php else: ?>
<meta property=“og:description” content=“<?php echo get_option(‘description’); ?>“ />
<?php endif; ?>
<?php } else { ?>
<meta property=“og:description” content=“<?php echo get_option(‘description’); ?>“ />
<?php } ?>
<meta property=“og:type” content=“website” />
<!— use default image if favicon not found —>
<?php if( file_exists( get_template_directory() . ‘/favicon.ico’ ) ) { ?>
<meta property=“og:image” content=“<?php echo get_template_directory_uri() . ‘/favicon.ico’; ?>“ />
<?php } else { ?>
<meta property=“og:image” content=“<?php echo get_template_directory_uri(); ?>/noimage.png” />
<?php } ?>
<?php } ?>
<?php }
// add action hook in wp_head()
add_action( ‘wp_head’, ‘insert_fbog_in_head’, 5 );
// function checks out
endif;
?>