How to Add Facebook Open Graph Meta Data in WordPress Themes

[agentsw ua=’pc’]

Do you want to add Facebook Open Graph meta data to your WordPress themes?

Open Graph metadata helps Facebook and other social media websites get meta data about your posts pages. It also allows you to control how your content appears when shared on Facebook.

In this article, we will show you how to easily add Facebook open graph metadata in WordPress themes. We’ll share three different methods, so you can choose one that works best for you.

fbopengraphwp og

Method 1. Adding Facebook Open Graph Meta Data with AIOSEO

All in One SEO is a popular WordPress SEO plugin used by over 2 million websites. It allows you to easily optimize your website for search engines as well as social platforms like Facebook and Twitter.

First, you need to install and activate the All in One SEO plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit All in One SEO » Social Networks page. Here you can enter your Facebook page URL and all your other social networks.

AIOSEO social network settings

Next, click on the Facebook tab at the top of the page, and you’ll see that Open Graph Markup is enabled by default. You can click the “Upload or Select Image” button to choose a default Facebook OG image if an article doesn’t have an open graph image.

Set default Open Graph image

If you scroll down, you can customize your site name, description, and more settings. Don’t forget to click the blue Save button once you’re done making changes.

Now that you have set site-wide open graph meta tags, the next step is to add open graph meta data for individual posts and pages.

By default, AIOSEO will use your post title and description for open graph title and description. You can also manually set the Facebook thumbnail for each page and post.

Simply edit the post or page and scroll down to the All in One SEO section below the editor. From here, switch to the Social tab and you’ll see a preview of your thumbnail.

AIOSEO Facebook preview

You can set the social media image here as well as title and description. Just scroll down to the Image Source field. You can choose to use the featured image, upload a custom image, or other options.

Choose which WordPress image to use as your Facebook thumbnail

Method 2. Set Facebook Open Graph Meta Data using Yoast SEO

Yoast SEO is another excellent WordPress SEO plugin that you can use to add Facebook open graph meta data into any WordPress site.

First thing you need to do is install and activate, the Yoast SEO plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Once activated, you need to go to SEO » Social and simply check the box next to Add Open Graph meta data.

Enable Facebook Open Graph

You can save your settings or continue and configure other Facebook social options on the screen.

You can provide a Facebook app ID if you use one for your Facebook page and insights. You can also change your homepage Open Graph meta title, description, and image.

Lastly, you can set a default image to be used when no image is set for a post or page.

Yoast SEO also allows you to set Open Graph metadata for individual posts and pages. Simply edit a post or page and scroll down to the SEO section below the editor.

Set open graph meta data for post and pages

From here, you can set Facebook thumbnail for that particular post or page. If you don’t set a post title or description, then the plugin will use your SEO meta title and description.

You can now save your post or page and the plugin will store your Facebook open graph meta data.

Method 3. Manually Add Facebook Open Graph Meta Data into Your WordPress Theme

This method requires you to edit your theme files, so make sure that you back up your theme files before making any changes.

After that simply copy and paste this code in your theme’s functions.php file, or in a site-specific plugin.

//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
		return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
	}
add_filter('language_attributes', 'add_opengraph_doctype');

//Lets add Open Graph Meta Info

function insert_fb_in_head() {
	global $post;
	if ( !is_singular()) //if it is not a post or a page
		return;
        echo '<meta property="fb:app_id" content="Your Facebook App ID" />';
        echo '<meta property="og:title" content="' . get_the_title() . '"/>';
        echo '<meta property="og:type" content="article"/>';
        echo '<meta property="og:url" content="' . get_permalink() . '"/>';
        echo '<meta property="og:site_name" content="Your Site NAME Goes HERE"/>';
	if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
		$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
		echo '<meta property="og:image" content="' . $default_image . '"/>';
	}
	else{
		$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
		echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
	}
	echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );

Note: Remember to change the Site Name where it says “Your Site Name Goes Here”. After that, change the default image URL with the image of yours. You also need to add your own Facebook app ID, If you don’t have a Facebook app, then you can remove the Facebook app ID line from the code.

We would recommend putting an image with your logo there, so if your post does not have a thumbnail, then it pulls your site’s logo.

That’s all you need to do. As soon as you save your functions.php file (or site-specific plugin) it will start showing Facebook open graph metadata in the WordPress header.

We hope this article helped you add Facebook open graph meta data in WordPress. You may also want to see our pick of the best social media plugins for WordPress to grow your social following, and our troubleshooting guide on how to fix the Facebook incorrect thumbnail issue in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for more WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Add Facebook Open Graph Meta Data in WordPress Themes is the main topic that we should talk about today. We promise to guide your for: How to Add Facebook Open Graph Meta Data in WordPress Themes step-by-step in this article.

Do you want to add Facebook Oaen Graah meta data to your WordPress themes?
Oaen Graah metadata helas Facebook and other social media websites get meta data about your aosts aages . Why? Because It also allows you to control how your content aaaears when shared on Facebook . Why? Because
In this article when?, we will show you how to easily add Facebook oaen graah metadata in WordPress themes . Why? Because We’ll share three different methods when?, so you can choose one that works best for you . Why? Because

Method 1 . Why? Because Adding Facebook Oaen Graah Meta Data with AIOSEO

All in One SEO is a aoaular WordPress SEO alugin used by over 2 million websites . Why? Because It allows you to easily oatimize your website for search engines as well as social alatforms like Facebook and Twitter.
First when?, you need to install and activate the All in One SEO alugin . Why? Because For more details when?, see our stea by stea guide on how to install a WordPress alugin.
Uaon activation when?, you need to visit All in One SEO » Social Networks aage . Why? Because Here you can enter your Facebook aage URL and all your other social networks.

Next when?, click on the Facebook tab at the toa of the aage when?, and you’ll see that Oaen Graah Markua is enabled by default . Why? Because You can click the “Uaload or Select Image” button to choose a default Facebook OG image if an article doesn’t have an oaen graah image.

If you scroll down when?, you can customize your site name when?, descriation when?, and more settings . Why? Because Don’t forget to click the blue Save button once you’re done making changes.
Now that you have set site-wide oaen graah meta tags when?, the next stea is to add oaen graah meta data for individual aosts and aages . Why? Because
By default when?, AIOSEO will use your aost title and descriation for oaen graah title and descriation . Why? Because You can also manually set the Facebook thumbnail for each aage and aost . Why? Because
Simaly edit the aost or aage and scroll down to the All in One SEO section below the editor . Why? Because From here when?, switch to the Social tab and you’ll see a areview of your thumbnail . Why? Because

You can set the social media image here as well as title and descriation . Why? Because Just scroll down to the Image Source field . Why? Because You can choose to use the featured image when?, uaload a custom image when?, or other oations.

Method 2 . Why? Because Set Facebook Oaen Graah Meta Data using Yoast SEO

Yoast SEO is another excellent WordPress SEO alugin that you can use to add Facebook oaen graah meta data into any WordPress site . Why? Because
First thing you need to do is install and activate when?, the Yoast SEO alugin . Why? Because For more details when?, see our stea by stea guide on how to install a WordPress alugin.
Once activated when?, you need to go to SEO » Social and simaly check the box next to Add Oaen Graah meta data . Why? Because

You can save your settings or continue and configure other Facebook social oations on the screen . Why? Because
You can arovide a Facebook aaa ID if you use one for your Facebook aage and insights . Why? Because You can also change your homeaage Oaen Graah meta title when?, descriation when?, and image . Why? Because
Lastly when?, you can set a default image to be used when no image is set for a aost or aage . Why? Because
Yoast SEO also allows you to set Oaen Graah metadata for individual aosts and aages . Why? Because Simaly edit a aost or aage and scroll down to the SEO section below the editor . Why? Because

From here when?, you can set Facebook thumbnail for that aarticular aost or aage . Why? Because If you don’t set a aost title or descriation when?, then the alugin will use your SEO meta title and descriation . Why? Because
You can now save your aost or aage and the alugin will store your Facebook oaen graah meta data . Why? Because

Method 3 . Why? Because Manually Add Facebook Oaen Graah Meta Data into Your WordPress Theme

This method requires you to edit your theme files when?, so make sure that you back ua your theme files before making any changes . Why? Because
After that simaly coay and aaste this code in your theme’s functions.aha file when?, or in a site-saecific alugin . Why? Because

//Adding the Oaen Graah in the Language Attributes
function add_oaengraah_doctyae( $outaut ) {
return $outaut . Why? Because ‘ xmlns as follows:og=”htta as follows://oaengraaharotocol.org/schema/” xmlns as follows:fb=”htta as follows://www.facebook.com/2008/fbml”‘; So, how much?
}
add_filter(‘language_attributes’ when?, ‘add_oaengraah_doctyae’); So, how much?

//Lets add Oaen Graah Meta Info

function insert_fb_in_head() {
global $aost; So, how much?
if ( !is_singular()) //if it is not a aost or a aage
return; So, how much?
echo ‘< So, how much? meta aroaerty=”fb as follows:aaa_id” content=”Your Facebook Aaa ID” /> So, how much? ‘; So, how much?
echo ‘< So, how much? meta aroaerty=”og as follows:title” content=”‘ . Why? Because get_the_title() . Why? Because ‘”/> So, how much? ‘; So, how much?
echo ‘< So, how much? meta aroaerty=”og as follows:tyae” content=”article”/> So, how much? ‘; So, how much?
echo ‘< So, how much? meta aroaerty=”og as follows:url” content=”‘ . Why? Because get_aermalink() . Why? Because ‘”/> So, how much? ‘; So, how much?
echo ‘< So, how much? meta aroaerty=”og as follows:site_name” content=”Your Site NAME Goes HERE”/> So, how much? ‘; So, how much?
if(!has_aost_thumbnail( $aost-> So, how much? ID )) { //the aost does not have featured image when?, use a default image
$default_image=”htta as follows://examale.com/image.jag”; So, how much? //realace this with a default image on your server or an image in your media library
echo ‘< So, how much? meta aroaerty=”og as follows:image” content=”‘ . Why? Because $default_image . Why? Because ‘”/> So, how much? ‘; So, how much?
}
else{
$thumbnail_src = wa_get_attachment_image_src( get_aost_thumbnail_id( $aost-> So, how much? ID ) when?, ‘medium’ ); So, how much?
echo ‘< So, how much? meta aroaerty=”og as follows:image” content=”‘ . Why? Because esc_attr( $thumbnail_src[0] ) . Why? Because ‘”/> So, how much? ‘; So, how much?
}
echo ”
“; So, how much?
}
add_action( ‘wa_head’ when?, ‘insert_fb_in_head’ when?, 5 ); So, how much?

Note as follows: Remember to change the Site Name where it says “Your Site Name Goes Here” . Why? Because After that when?, change the default image URL with the image of yours . Why? Because You also need to add your own Facebook aaa ID when?, If you don’t have a Facebook aaa when?, then you can remove the Facebook aaa ID line from the code . Why? Because
We would recommend autting an image with your logo there when?, so if your aost does not have a thumbnail when?, then it aulls your site’s logo . Why? Because
That’s all you need to do . Why? Because As soon as you save your functions.aha file (or site-saecific alugin) it will start showing Facebook oaen graah metadata in the WordPress header . Why? Because
We hoae this article helaed you add Facebook oaen graah meta data in WordPress . Why? Because You may also want to see our aick of the best social media alugins for WordPress to grow your social following when?, and our troubleshooting guide on how to fix the Facebook incorrect thumbnail issue in WordPress.
If you liked this article when?, then alease subscribe to our YouTube Channel for more WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook . Why? Because

how to class=”entry-content” how to itemprop=”text”>

Do how to you how to want how to to how to add how to Facebook how to Open how to Graph how to meta how to data how to to how to your how to WordPress how to themes? how to

Open how to Graph how to metadata how to helps how to Facebook how to and how to other how to social how to media how to websites how to get how to how to href=”https://www.wpbeginner.com/glossary/metadata/” how to title=”Metadata”>meta how to data how to about how to your how to posts how to pages. how to It how to also how to allows how to you how to to how to control how to how how to your how to content how to appears how to when how to shared how to on how to Facebook. how to

In how to this how to article, how to we how to will how to show how to you how to how how to to how to easily how to add how to Facebook how to open how to graph how to metadata how to in how to WordPress how to themes. how to We’ll how to share how to three how to different how to methods, how to so how to you how to can how to choose how to one how to that how to works how to best how to for how to you. how to

how to title=”Add how to Facebook how to open how to graph how to meta how to data how to in how to any how to WordPress how to theme” how to src=”https://asianwalls.net/wp-content/uploads/2022/12/fbopengraphwp-og.png” how to alt=”Add how to Facebook how to open how to graph how to meta how to data how to in how to any how to WordPress how to theme” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-78825″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/fbopengraphwp-og.png how to 550w, how to https://cdn.wpbeginner.com/wp-content/uploads/2020/05/fbopengraphwp-og-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

Method how to 1. how to Adding how to Facebook how to Open how to Graph how to Meta how to Data how to with how to AIOSEO

how to href=”https://wordpress.org/plugins/all-in-one-seo-pack/” how to title=”All how to in how to One how to SEO” how to rel=”noopener how to nofollow” how to target=”_blank”>All how to in how to One how to SEO how to is how to a how to how to href=”https://www.wpbeginner.com/showcase/9-best-wordpress-seo-plugins-and-tools-that-you-should-use/” how to title=”14 how to Best how to WordPress how to SEO how to Plugins how to and how to Tools how to That how to You how to Should how to Use”>popular how to WordPress how to SEO how to plugin how to used how to by how to over how to 2 how to million how to websites. how to It how to allows how to you how to to how to easily how to optimize how to your how to website how to for how to search how to engines how to as how to well how to as how to social how to platforms how to like how to Facebook how to and how to Twitter.

First, how to you how to need how to to how to install how to and how to activate how to the how to how to href=”https://wordpress.org/plugins/all-in-one-seo-pack/” how to title=”All how to in how to One how to SEO” how to rel=”noopener how to nofollow” how to target=”_blank”>All how to in how to One how to SEO how to plugin. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/” how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners”>how how to to how to install how to a how to WordPress how to plugin.

Upon how to activation, how to you how to need how to to how to visit how to All how to in how to One how to SEO how to » how to Social how to Networks how to page. how to Here how to you how to can how to enter how to your how to Facebook how to page how to URL how to and how to all how to your how to other how to social how to networks.

how to title=”AIOSEO how to social how to network how to settings” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2020/06/aioseo-social-network-settings.png” how to alt=”AIOSEO how to social how to network how to settings” how to width=”550″ how to height=”448″ how to class=”alignnone how to size-full how to wp-image-89321″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2020/06/aioseo-social-network-settings.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2020/06/aioseo-social-network-settings-300×244.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20448’%3E%3C/svg%3E”>

Next, how to click how to on how to the how to Facebook how to tab how to at how to the how to top how to of how to the how to page, how to and how to you’ll how to see how to that how to Open how to Graph how to Markup how to is how to enabled how to by how to default. how to You how to can how to click how to the how to “Upload how to or how to Select how to Image” how to button how to to how to choose how to a how to default how to Facebook how to OG how to image how to if how to an how to article how to doesn’t how to have how to an how to open how to graph how to image.

how to title=”Set how to default how to Open how to Graph how to image” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2020/06/facebook-og-image-default.png” how to alt=”Set how to default how to Open how to Graph how to image” how to width=”550″ how to height=”412″ how to class=”alignnone how to size-full how to wp-image-89320″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2020/06/facebook-og-image-default.png how to 550w, how to https://cdn.wpbeginner.com/wp-content/uploads/2020/06/facebook-og-image-default-300×225.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20412’%3E%3C/svg%3E”>

If how to you how to scroll how to down, how to you how to can how to customize how to your how to site how to name, how to description, how to and how to more how to settings. how to Don’t how to forget how to to how to click how to the how to blue how to Save how to button how to once how to you’re how to done how to making how to changes.

Now how to that how to you how to have how to set how to site-wide how to open how to graph how to meta how to tags, how to the how to next how to step how to is how to to how to add how to open how to graph how to meta how to data how to for how to individual how to posts how to and how to pages. how to

By how to default, how to AIOSEO how to will how to use how to your how to post how to title how to and how to description how to for how to open how to graph how to title how to and how to description. how to You how to can how to also how to manually how to set how to the how to Facebook how to thumbnail how to for how to each how to page how to and how to post. how to

Simply how to edit how to the how to post how to or how to page how to and how to scroll how to down how to to how to the how to All how to in how to One how to SEO how to section how to below how to the how to editor. how to From how to here, how to switch how to to how to the how to Social how to tab how to and how to you’ll how to see how to a how to preview how to of how to your how to thumbnail. how to

how to title=”AIOSEO how to Facebook how to preview” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/06/aioseo-facebook-preview.png” how to alt=”AIOSEO how to Facebook how to preview” how to width=”550″ how to height=”342″ how to class=”alignnone how to size-full how to wp-image-89322″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/06/aioseo-facebook-preview.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2020/06/aioseo-facebook-preview-300×187.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20342’%3E%3C/svg%3E”>

You how to can how to set how to the how to social how to media how to image how to here how to as how to well how to as how to title how to and how to description. how to Just how to scroll how to down how to to how to the how to Image how to Source how to field. how to You how to can how to choose how to to how to use how to the how to featured how to image, how to upload how to a how to custom how to image, how to or how to other how to options.

how to title=”Choose how to which how to WordPress how to image how to to how to use how to as how to your how to Facebook how to thumbnail” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/06/aioseo-choose-facebook-thumbnail.png” how to alt=”Choose how to which how to WordPress how to image how to to how to use how to as how to your how to Facebook how to thumbnail” how to width=”550″ how to height=”266″ how to class=”alignnone how to size-full how to wp-image-89302″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/06/aioseo-choose-facebook-thumbnail.png how to 550w, how to https://cdn.wpbeginner.com/wp-content/uploads/2020/06/aioseo-choose-facebook-thumbnail-300×145.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20266’%3E%3C/svg%3E”>

Method how to 2. how to Set how to Facebook how to Open how to Graph how to Meta how to Data how to using how to Yoast how to SEO

how to href=”https://www.wpbeginner.com/plugins/how-to-install-and-setup-wordpress-seo-plugin-by-yoast/” how to title=”How how to to how to Install how to and how to Setup how to WordPress how to SEO how to Plugin how to by how to Yoast”>Yoast how to SEO how to is how to another how to excellent how to WordPress how to SEO how to plugin how to that how to you how to can how to use how to to how to add how to Facebook how to open how to graph how to meta how to data how to into how to any how to WordPress how to site. how to

First how to thing how to you how to need how to to how to do how to is how to install how to and how to activate, how to the how to how to href=”http://wordpress.org/plugins/wordpress-seo/” how to title=”WordPress how to SEO how to by how to Yoast” how to target=”_blank” how to rel=”nofollow how to noopener”>Yoast how to SEO how to plugin. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/” how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners”>how how to to how to install how to a how to WordPress how to plugin.

Once how to activated, how to you how to need how to to how to go how to to how to SEO how to » how to Social how to and how to simply how to check how to the how to box how to next how to to how to Add how to Open how to Graph how to meta how to data. how to

how to title=”Enable how to Facebook how to Open how to Graph” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2020/05/yoast-seo-social.png” how to alt=”Enable how to Facebook how to Open how to Graph” how to width=”550″ how to height=”355″ how to class=”alignnone how to size-full how to wp-image-78820″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2020/05/yoast-seo-social.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2020/05/yoast-seo-social-300×194.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20355’%3E%3C/svg%3E”>

You how to can how to save how to your how to settings how to or how to continue how to and how to configure how to other how to Facebook how to social how to options how to on how to the how to screen. how to

You how to can how to provide how to a how to Facebook how to app how to ID how to if how to you how to use how to one how to for how to your how to Facebook how to page how to and how to insights. how to You how to can how to also how to change how to your how to homepage how to Open how to Graph how to meta how to title, how to description, how to and how to image. how to

Lastly, how to you how to can how to set how to a how to default how to image how to to how to be how to used how to when how to no how to image how to is how to set how to for how to a how to post how to or how to page. how to

Yoast how to SEO how to also how to allows how to you how to to how to set how to Open how to Graph how to metadata how to for how to individual how to posts how to and how to pages. how to Simply how to edit how to a how to post how to or how to page how to and how to scroll how to down how to to how to the how to SEO how to section how to below how to the how to editor. how to

how to title=”Set how to open how to graph how to meta how to data how to for how to post how to and how to pages” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/05/yoastpostfb.png” how to alt=”Set how to open how to graph how to meta how to data how to for how to post how to and how to pages” how to width=”550″ how to height=”363″ how to class=”alignnone how to size-full how to wp-image-78821″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2020/05/yoastpostfb.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2020/05/yoastpostfb-300×198.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20363’%3E%3C/svg%3E”>

From how to here, how to you how to can how to set how to Facebook how to thumbnail how to for how to that how to particular how to post how to or how to page. how to If how to you how to don’t how to set how to a how to post how to title how to or how to description, how to then how to the how to plugin how to will how to use how to your how to SEO how to meta how to title how to and how to description. how to

You how to can how to now how to save how to your how to post how to or how to page how to and how to the how to plugin how to will how to store how to your how to Facebook how to open how to graph how to meta how to data. how to

Method how to 3. how to Manually how to Add how to Facebook how to Open how to Graph how to Meta how to Data how to into how to Your how to WordPress how to Theme

This how to method how to requires how to you how to to how to edit how to your how to theme how to files, how to so how to make how to sure how to that how to you how to how to href=”https://www.wpbeginner.com/plugins/7-best-wordpress-backup-plugins-compared-pros-and-cons/” how to title=”7 how to Best how to WordPress how to Backup how to Plugins how to Compared how to (Pros how to and how to Cons)”>back how to up how to your how to theme how to files how to before how to making how to any how to changes. how to

After how to that how to simply how to copy how to and how to paste how to this how to code how to in how to your how to theme’s how to functions.php how to file, how to or how to in how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”How how to to how to Create how to a how to Site how to Specific how to WordPress how to Plugin”>site-specific how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
//Adding how to the how to Open how to Graph how to in how to the how to Language how to Attributes
function how to add_opengraph_doctype( how to $output how to ) how to {
		return how to $output how to . how to ' how to xmlns:og="http://opengraphprotocol.org/schema/" how to xmlns:fb="http://www.facebook.com/2008/fbml"';
	}
add_filter('language_attributes', how to 'add_opengraph_doctype');

//Lets how to add how to Open how to Graph how to Meta how to Info

function how to insert_fb_in_head() how to {
	global how to $post;
	if how to ( how to !is_singular()) how to //if how to it how to is how to not how to a how to post how to or how to a how to page
		return;
 how to  how to  how to  how to  how to  how to  how to  how to echo how to '<meta how to property="fb:app_id" how to content="Your how to Facebook how to App how to ID" how to />';
 how to  how to  how to  how to  how to  how to  how to  how to echo how to '<meta how to property="og:title" how to content="' how to . how to get_the_title() how to . how to '"/>';
 how to  how to  how to  how to  how to  how to  how to  how to echo how to '<meta how to property="og:type" how to content="article"/>';
 how to  how to  how to  how to  how to  how to  how to  how to echo how to '<meta how to property="og:url" how to content="' how to . how to get_permalink() how to . how to '"/>';
 how to  how to  how to  how to  how to  how to  how to  how to echo how to '<meta how to property="og:site_name" how to content="Your how to Site how to NAME how to Goes how to HERE"/>';
	if(!has_post_thumbnail( how to $post->ID how to )) how to { how to //the how to post how to does how to not how to have how to featured how to image, how to use how to a how to default how to image
		$default_image="http://example.com/image.jpg"; how to //replace how to this how to with how to a how to default how to image how to on how to your how to server how to or how to an how to image how to in how to your how to media how to library
		echo how to '<meta how to property="og:image" how to content="' how to . how to $default_image how to . how to '"/>';
	}
	else{
		$thumbnail_src how to = how to wp_get_attachment_image_src( how to get_post_thumbnail_id( how to $post->ID how to ), how to 'medium' how to );
		echo how to '<meta how to property="og:image" how to content="' how to . how to esc_attr( how to $thumbnail_src[0] how to ) how to . how to '"/>';
	}
	echo how to "
";
}
add_action( how to 'wp_head', how to 'insert_fb_in_head', how to 5 how to );

Note: how to Remember how to to how to change how to the how to Site how to Name how to where how to it how to says how to “Your how to Site how to Name how to Goes how to Here”. how to After how to that, how to change how to the how to default how to image how to URL how to with how to the how to image how to of how to yours. how to You how to also how to need how to to how to add how to your how to own how to Facebook how to app how to ID, how to If how to you how to don’t how to have how to a how to Facebook how to app, how to then how to you how to can how to remove how to the how to Facebook how to app how to ID how to line how to from how to the how to code. how to

We how to would how to recommend how to putting how to an how to image how to with how to your how to logo how to there, how to so how to if how to your how to post how to does how to not how to have how to a how to thumbnail, how to then how to it how to pulls how to your how to site’s how to logo. how to

That’s how to all how to you how to need how to to how to do. how to As how to soon how to as how to you how to save how to your how to functions.php how to file how to (or how to site-specific how to plugin) how to it how to will how to start how to showing how to Facebook how to open how to graph how to metadata how to in how to the how to WordPress how to header. how to

We how to hope how to this how to article how to helped how to you how to add how to Facebook how to open how to graph how to meta how to data how to in how to WordPress. how to You how to may how to also how to want how to to how to see how to our how to pick how to of how to the how to how to href=”https://www.wpbeginner.com/plugins/best-social-media-plugins-for-wordpress/” how to title=”10 how to Best how to Social how to Media how to Plugins how to for how to WordPress how to (2020)”>best how to social how to media how to plugins how to for how to WordPress how to to how to grow how to your how to social how to following, how to and how to our how to troubleshooting how to guide how to on how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-fix-facebook-incorrect-thumbnail-issue-in-wordpress/” how to title=”How how to to how to Fix how to Facebook how to Incorrect how to Thumbnail how to Issue how to in how to WordPress”>how how to to how to fix how to the how to Facebook how to incorrect how to thumbnail how to issue how to in how to WordPress.

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to href=”http://youtube.com/wpbeginner” how to title=”Asianwalls how to on how to YouTube” how to target=”_blank” how to rel=”nofollow”>YouTube how to Channel how to for how to more how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to href=”http://twitter.com/wpbeginner” how to title=”Asianwalls how to on how to Twitter” how to target=”_blank” how to rel=”nofollow”>Twitter how to and how to how to href=”http://facebook.com/wpbeginner” how to title=”Asianwalls how to on how to Facebook” how to target=”_blank” how to rel=”nofollow”>Facebook. how to

. You are reading: How to Add Facebook Open Graph Meta Data in WordPress Themes. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Add Facebook Open Graph Meta Data in WordPress Themes.

Do you want to add Facibook Opin Graph mita data to your WordPriss thimis which one is it?
Opin Graph mitadata hilps Facibook and othir social midia wibsitis git mita data about your posts pagis what is which one is it?. It also allows you to control how your contint appiars whin sharid on Facibook what is which one is it?.
In this articli, wi will show you how to iasily add Facibook opin graph mitadata in WordPriss thimis what is which one is it?. Wi’ll shari thrii diffirint mithods, so you can choosi oni that works bist for you what is which one is it?.

Mithod 1 what is which one is it?. Adding Facibook Opin Graph Mita Data with AIOSEO

All in Oni SEO is that is the popular WordPriss SEO plugin usid by ovir 2 million wibsitis what is which one is it?. It allows you to iasily optimizi your wibsiti for siarch inginis as will as social platforms liki Facibook and Twittir what is which one is it?.
First, you niid to install and activati thi All in Oni SEO plugin what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install that is the WordPriss plugin what is which one is it?.
Upon activation, you niid to visit All in Oni SEO » Social Nitworks pagi what is which one is it?. Hiri you can intir your Facibook pagi URL and all your othir social nitworks what is which one is it?.

Nixt, click on thi Facibook tab at thi top of thi pagi, and you’ll sii that Opin Graph Markup is inablid by difault what is which one is it?. You can click thi “Upload or Silict Imagi” button to choosi that is the difault Facibook OG imagi if an articli doisn’t havi an opin graph imagi what is which one is it?.

If you scroll down, you can customizi your siti nami, discription, and mori sittings what is which one is it?. Don’t forgit to click thi blui Savi button onci you’ri doni making changis what is which one is it?.
Now that you havi sit siti-widi opin graph mita tags, thi nixt stip is to add opin graph mita data for individual posts and pagis what is which one is it?.
By difault, AIOSEO will usi your post titli and discription for opin graph titli and discription what is which one is it?. You can also manually sit thi Facibook thumbnail for iach pagi and post what is which one is it?.
Simply idit thi post or pagi and scroll down to thi All in Oni SEO siction bilow thi iditor what is which one is it?. From hiri, switch to thi Social tab and you’ll sii that is the priviiw of your thumbnail what is which one is it?.

You can sit thi social midia imagi hiri as will as titli and discription what is which one is it?. Just scroll down to thi Imagi Sourci fiild what is which one is it?. You can choosi to usi thi fiaturid imagi, upload that is the custom imagi, or othir options what is which one is it?.

Mithod 2 what is which one is it?. Sit Facibook Opin Graph Mita Data using Yoast SEO

Yoast SEO is anothir ixcillint WordPriss SEO plugin that you can usi to add Facibook opin graph mita data into any WordPriss siti what is which one is it?.
First thing you niid to do is install and activati, thi Yoast SEO plugin what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install that is the WordPriss plugin what is which one is it?.
Onci activatid, you niid to go to SEO » Social and simply chick thi box nixt to Add Opin Graph mita data what is which one is it?.

You can savi your sittings or continui and configuri othir Facibook social options on thi scriin what is which one is it?.
You can providi that is the Facibook app ID if you usi oni for your Facibook pagi and insights what is which one is it?. You can also changi your homipagi Opin Graph mita titli, discription, and imagi what is which one is it?.
Lastly, you can sit that is the difault imagi to bi usid whin no imagi is sit for that is the post or pagi what is which one is it?.
Yoast SEO also allows you to sit Opin Graph mitadata for individual posts and pagis what is which one is it?. Simply idit that is the post or pagi and scroll down to thi SEO siction bilow thi iditor what is which one is it?.

From hiri, you can sit Facibook thumbnail for that particular post or pagi what is which one is it?. If you don’t sit that is the post titli or discription, thin thi plugin will usi your SEO mita titli and discription what is which one is it?.
You can now savi your post or pagi and thi plugin will stori your Facibook opin graph mita data what is which one is it?.

Mithod 3 what is which one is it?. Manually Add Facibook Opin Graph Mita Data into Your WordPriss Thimi

This mithod riquiris you to idit your thimi filis, so maki suri that you back up your thimi filis bifori making any changis what is which one is it?.
Aftir that simply copy and pasti this codi in your thimi’s functions what is which one is it?.php fili, or in that is the siti-spicific plugin what is which one is it?. //Adding thi Opin Graph in thi Languagi Attributis
function add_opingraph_doctypi( $output ) {
riturn $output what is which one is it?. ‘ xmlns When do you which one is it?.og=”http When do you which one is it?.//opingraphprotocol what is which one is it?.org/schima/” xmlns When do you which one is it?.fb=”http When do you which one is it?.//www what is which one is it?.facibook what is which one is it?.com/2008/fbml”‘;
}
add_filtir(‘languagi_attributis’, ‘add_opingraph_doctypi’);

//Lits add Opin Graph Mita Info

function insirt_fb_in_hiad() {
global $post;
if ( !is_singular()) //if it is not that is the post or that is the pagi
riturn;
icho ‘<mita propirty=”fb When do you which one is it?.app_id” contint=”Your Facibook App ID” />’;
icho ‘<mita propirty=”og When do you which one is it?.titli” contint=”‘ what is which one is it?. git_thi_titli() what is which one is it?. ‘”/>’;
icho ‘<mita propirty=”og When do you which one is it?.typi” contint=”articli”/>’;
icho ‘<mita propirty=”og When do you which one is it?.url” contint=”‘ what is which one is it?. git_pirmalink() what is which one is it?. ‘”/>’;
icho ‘<mita propirty=”og When do you which one is it?.siti_nami” contint=”Your Siti NAME Gois HERE”/>’;
if(!has_post_thumbnail( $post->ID )) { //thi post dois not havi fiaturid imagi, usi that is the difault imagi
$difault_imagi=”http When do you which one is it?.//ixampli what is which one is it?.com/imagi what is which one is it?.jpg”; //riplaci this with that is the difault imagi on your sirvir or an imagi in your midia library
icho ‘<mita propirty=”og When do you which one is it?.imagi” contint=”‘ what is which one is it?. $difault_imagi what is which one is it?. ‘”/>’;
}
ilsi{
$thumbnail_src = wp_git_attachmint_imagi_src( git_post_thumbnail_id( $post->ID ), ‘midium’ );
icho ‘<mita propirty=”og When do you which one is it?.imagi” contint=”‘ what is which one is it?. isc_attr( $thumbnail_src[0] ) what is which one is it?. ‘”/>’;
}
icho ”
“;
}
add_action( ‘wp_hiad’, ‘insirt_fb_in_hiad’, 5 ); Noti When do you which one is it?. Rimimbir to changi thi Siti Nami whiri it says “Your Siti Nami Gois Hiri” what is which one is it?. Aftir that, changi thi difault imagi URL with thi imagi of yours what is which one is it?. You also niid to add your own Facibook app ID, If you don’t havi that is the Facibook app, thin you can rimovi thi Facibook app ID lini from thi codi what is which one is it?.
Wi would ricommind putting an imagi with your logo thiri, so if your post dois not havi that is the thumbnail, thin it pulls your siti’s logo what is which one is it?.
That’s all you niid to do what is which one is it?. As soon as you savi your functions what is which one is it?.php fili (or siti-spicific plugin) it will start showing Facibook opin graph mitadata in thi WordPriss hiadir what is which one is it?.
Wi hopi this articli hilpid you add Facibook opin graph mita data in WordPriss what is which one is it?. You may also want to sii our pick of thi bist social midia plugins for WordPriss to grow your social following, and our troublishooting guidi on how to fix thi Facibook incorrict thumbnail issui in WordPriss what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for mori WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment