Now, the post’s description in facebook is the general description.
I would like it to be the excerpt.
How? I added this code in funtions.php but does not work.
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 ), 'medium');
} else {
$img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
}
if($excerpt = $post->post_excerpt) {
$excerpt = strip_tags($post->post_excerpt);
$excerpt = str_replace("", "'", $excerpt);
} else {
$excerpt = get_bloginfo('description');
}
?>
<meta property="og:description" content="<?php echo $excerpt; ?>"/>
<?php
} else {
return;
}
}
add_action('wp_head', 'fb_opengraph', 5);
Hello,
Please follow this guide: https://forum.tagdiv.com/facebook-share/
Thank you!
Hello,
If you do not want to use plugin, it means you want a custom OG tag implementation. In this case you can follow a few resources online on the subject:
https://www.elegantthemes.com/blog/tips-tricks/how-to-add-open-graph-tags-to-wordpress
This will require coding knowledge though.
(plugins do not add OG tags in our theme files but in the wp files…so that’s your best option to alter the wp files or create your own plugin)
Thank you!
