Skip to content

Instantly share code, notes, and snippets.

@ahsannayem
Last active January 16, 2025 06:32
Show Gist options
  • Save ahsannayem/af1ac8aea244d6c4d6a3fa651a86d7a2 to your computer and use it in GitHub Desktop.
Save ahsannayem/af1ac8aea244d6c4d6a3fa651a86d7a2 to your computer and use it in GitHub Desktop.
The featured image is not shown when adding the post link on FluentCommunity or any social platform
function add_open_graph_tags() {
if (is_single() || is_page()) {
global $post;
$featured_image = get_the_post_thumbnail_url($post->ID, 'full');
$default_image = 'https://verenakrone.de/path-to-default-image.jpg'; // Replace with your default image URL
?>
<meta property="og:title" content="<?php echo get_the_title(); ?>" />
<meta property="og:description" content="<?php echo get_the_excerpt(); ?>" />
<meta property="og:image" content="<?php echo $featured_image ? $featured_image : $default_image; ?>" />
<meta property="og:url" content="<?php echo get_permalink(); ?>" />
<meta property="og:type" content="article" />
<?php
}
}
add_action('wp_head', 'add_open_graph_tags');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment