Skip to content

Instantly share code, notes, and snippets.

@mahfuj156
Created September 1, 2020 08:56
Show Gist options
  • Save mahfuj156/c4b49feb8725fa0e3e6e7568c4c4ba89 to your computer and use it in GitHub Desktop.
Save mahfuj156/c4b49feb8725fa0e3e6e7568c4c4ba89 to your computer and use it in GitHub Desktop.
How to create a dynamic Open Graph (OG) image for your website by WordPress
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-thumbnail' ); ?>
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:description" content="" />
<meta property="og:image" content="<?php echo $image[0]; ?>" />
<meta property="og:video" content="" />
<meta property="og:video:width" content="560" />
<meta property="og:video:height" content="340" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment