Add the following code to your WordPress theme’s function.php file, or a functionality plugin to add Open Graph To Genesis.
/** ADD OPEN GRAPH TO GENESIS THEME
//* Call the First Image in a Post (Used in the Open Graph Call Below)
function catch_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Define default image
$first_img = "/images/defalut.jpg";
}
return $first_img;
}
//* Add Open Graph meta tag to Head
add_action( 'genesis_meta', 'fb_opengraph' );
function fb_opengraph() {
global $post;
if( has_post_thumbnail( $post->ID ) ) {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' )[0];
}
else {
$img_src = catch_first_image();
}
?>
<?php
}
Share Your Two Cents