Easy Way to Add Knowledge Graph to WordPress Without a Plugin

Categories: Wordpress, SEO

In this article, I am going to show you how to easily add Knowledge Graph to WordPress manually (without the use of plugins)

The Google’s Knowledge Graph is the big block of information that appears on the right-hand side of Google’s search results. The Knowledge Graph contains relevant, context-specific information, regarding your search. For example, if you search for Pablo Picasso in Google, you will see images and information regarding the famous painter on the right-hand side of your screen. In a similar way, If you search for a company, e.g. “Apple”, you will find lots of useful information such as address, contact, short description about the business, products, as well as information about its founders and executives.

Adding schema markup to WordPress can help Google find the relevant information and create a Knowledge Graph for your website. Knowledge Graph can be added via different encodings, the most popular being Microdata, RDF-a and JSON-LD. We will have a closer look at JSON-LD file format, since it is in my opinion the most user-friendly and it is also the prefered method by Google. Please note that whether your website will appear in the Google’s Knowledge Graph or not depends entirely on Google. In any case, adding the necessary information will have a positive effect on your website’s SEO.

To add Knowledgre Graph schema markup to WordPress, add the following code to your child theme’s functions.php file:

function add_knowledgegraph() {
echo "\n<!-- KNOWLEDGE GRAPH -->";
if (is_front_page()) {
echo '
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Organization",
  "name": " My awesome website",
  "url": "http://yourwebsite.com",
  "logo": "http://yourwebsite.com/logo.jpg",
  "description": "My awesome website’s description",
  "foundingDate": "2014",
  "founders": [
	 {
	 "@type": "Person",
	 "name": "Mark Spencer"
	 },
	 {
	 "@type": "Person",
	 "name": "John Doe"
	} ], 
  "contactPoint" : [
    { "@type" : "ContactPoint",
      "email": "example@mail.com"
    } ],
  "sameAs" : [
    "http://www.facebook.com/ ",
    "https://www.twitter.com/ ",
    "https://www.linkedin.com/ "
  ]}
</script>';
}
echo "\n\n";	
}
add_action('wp_head', 'add_knowledgegraph');
The code adds JSON-LD schema markup in the head of your website’s home page. In this way, you can easily add Knowledge Graph schema markup to Wordpress without the use of plugins. You only need to change the right-hand side values with the relevant information. The following example can be used to add different types of schema markup to any post or page.

Happy coding!

Read more: