I could really use some help on this one, its driving me nuts.
Im creating an image site in wordpress, and I would like my post to be shared, with only big images on Facebook. Kinda like a .gif but the image files are .jpg nor .png
To clearify what i need, take a look at this:
I really dont care about the faults, Just want to share big images. So the site im linking to is a PHP fuision site. Ive talked to the guy that runs it. And ive gotten the code from him.
The code look like this;
if ($data['photo_gif']=="1")
{
add_to_head('<meta property="og:image" content="'.$settings['siteurl'].''.$photo_file.'">');
add_to_head('<meta property="og:image:width" content="'.$photo_size[0].'" />');
add_to_head('<meta property="og:image:height" content="'.$photo_size[1].'" />');
add_to_head('<meta property="og:title" content="'.$data['photo_title'].'">');
add_to_head('<meta property="og:description" content="'.$settings['description'].'">');
add_to_head('<meta property="og:url" content="'.$settings['siteurl'].''.$photo_file.'">');
add_to_head('<meta property="og:type" content="video.movie">');
add_to_head('<meta property="og:video" content="'.$settings['siteurl'].''.$photo_file.'">');
}
else
{
add_to_head('<meta property="og:image" content="'.$settings['siteurl'].''.$photo_file.'">');
add_to_head('<meta property="og:image:width" content="'.$photo_size[0].'" />');
add_to_head('<meta property="og:image:height" content="'.$photo_size[1].'" />');
add_to_head('<meta property="og:title" content="'.$data['photo_title'].'">');
add_to_head('<meta property="og:description" content="'.$settings['sitename'].'">');
add_to_head('<meta property="og:url" content="'.$settings['siteurl'].'photogallery.php?photo_id='.$_GET['photo_id'].'">');
add_to_head('<meta property="og:type" content="website" />');
}
On his site, he has the option to pick if he want to share big images or not. I just want my site to only share big images. He said that the key point is to make the og:image and the og:url the same. Using the image path.
So i tried to do this, what wordpress echo strings. This is my code:
function doctype_opengraph($output) {
return $output . '
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'doctype_opengraph');
function fb_opengraph() {
global $post;
if(is_single()) {
if(has_post_thumbnail($post->ID)) {
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full');
} else {
$img_src = get_stylesheet_directory_uri() . 'http://dinfrækert.dk/wp-content/uploads/2016/12/dinfraekert_dk.png';
}
if($excerpt = $post->post_excerpt) {
$excerpt = strip_tags($post->post_excerpt);
$excerpt = str_replace("", "'", $excerpt);
} else {
$excerpt = get_bloginfo('description');
}
?>
<meta property="og:title" content="<?php echo the_title(); ?>"/>
<meta property="og:description" content="<?php echo $excerpt; ?>"/>
<meta property="og:type" content="video.movie"/>
<meta property="og:url" content="<?php echo $img_src; ?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
<meta property="og:image" content="<?php echo $img_src; ?>"/>
<meta property="og:video" content="<?php echo $img_src; ?>"/>
<?php
} else {
return;
}
}
add_action('wp_head', 'fb_opengraph', 5);
This is kinda working. Well not really. but its give me some kind of output. This is what it looks like i post sourcecode after implamentet the script. Ive putted it in functions.php btw.
<meta property="og:title" content="Kravlenisse."/>
<meta property="og:description" content="Frække og sjove ting dagligt"/>
<meta property="og:type" content="video.movie"/>
<meta property="og:url" content="Array"/>
<meta property="og:site_name" content="Din frækkert"/>
<meta property="og:image" content="Array"/>
<meta property="og:video" content="Array"/>
Im getting the "Array" fault. Really hoping someone could help me!
</div>