How to Add Open Graph without Plugins | WordPress

open-graphWhen you share your post on social media, Then post’s icon not show on shared post. So add given code on your website’s theme and show post’s icon , title name or else.

How to  Do

Open active theme’s header.php file then paste given code between <head>….. </head>

<?php if(is_single() ) {
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?php echo get_permalink() ?>" />
<meta property="og:site_name" content="<?php bloginfo('name') ?>" />
<meta property="og:image" content="<?php
if ( has_post_thumbnail($post->ID) ) {
the_post_thumbnail_url( 'small-thumbnail' );
}
else {
echo get_site_icon_url();
} ?>" />
} ?>

Then SAVE header.php file.

Hope fully you have added this code on website and code will perfectly worked. Thanks for visiting