Over a million developers have joined DZone.

Dramatically Increase Visibility in Search for WordPress Using JSON-LD Payloads and This PHP Snippet

WordPress runs about 25% of the internet and holds one of the all-time records for adoption. But, managing its search presence is sloppy, difficult, and inexact. JSON-LD and PHP can fix this.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

WordPress may not be ideal. It may not be coherent in terms of its user experience. It may not offer granular enough control. And editing its source files is mostly trouble. 

But, it is everywhere and about as difficult to avoid as oxygen. Chances are, you'll be called upon to work with WordPress at some point in your career, because it's not going anywhere soon. 

Search Me

SEO is usually managed from within WordPress by a variety of plugins—usually, not just one is sufficient. Most are missing crucial components like the ability to generate DublinCore here or Schema.org information there. (And, we know how well WordPress manages dependencies and conflicts—which is to say, it doesn't.)

This is a pain point for SEOs, who may not necessarily have the knowledge to implement schema.org. Almost no web developer wants to implement any of this microformat or semantic tagging in HTML, by hand. It's messy, and depending on the theme files and whatever else is going on, you may not actually be able to put your information correctly into the "loop."

Implementing in Less Than 100 Lines

Modify header.php to include:

<?php include('json-ld.php'); ?>
<script type="application/ld+json"><?php echo json_encode($payload); ?></script>

Create json-ld.php for your theme:

// JSON-LD for Wordpress Home Articles and Author Pages (by Pete Wailes and Richard Baxter)
function get_post_data() {
  global $post;
  return $post;

// Any Page
$payload["@context"] = "http://schema.org/";

// Data of the post/page
$post_data = get_post_data();

// Any page, if it exists
$category = get_the_category();

// Specific Pages
if (is_single()) {
  // this gets the data for the user who wrote that particular item
  $author_data = get_userdata($post_data->post_author);
  $post_url = get_permalink();
  $post_thumb = wp_get_attachment_url(get_post_thumbnail_id($post->ID));

  $payload["@type"] = "Article";
  $payload["url"] = $post_url;
  $payload["author"] = array(
      "@type" => "Person",
      "name" => $author_data->display_name,
  $payload["headline"] = $post_data->post_title;
  $payload["datePublished"] = $post_data->post_date;
  $payload["image"] = $post_thumb;
  $payload["ArticleSection"] = $category[0]->cat_name;
  $payload["Publisher"] = "Builtvisible";

// we do all this separately so we keep the right things for organization together

if (is_front_page()) {
  $payload["@type"] = "Organization";
  $payload["name"] = "Builtvisible";
  $payload["logo"] = "http://<your domain>.com/wp-content/uploads/logo.png";
  $payload["url"] = "http://<your domain>.com/";
  $payload["sameAs"] = array(
  $payload["contactPoint"] = array(
      "@type" => "ContactPoint",
      "telephone" => "+8005555555",
      "email" => "help@<your domain>.com",
      "contactType" => "sales"

if (is_author()) {
  // this gets the data for the user who wrote that particular item
  $author_data = get_userdata($post_data->post_author);

  // some of you may not have all of these data points in your user profiles - delete as appropriate
  // fetch twitter from author meta and concatenate with full twitter URL
  $twitter_url =  " https://twitter.com/";
  $twitterHandle = get_the_author_meta('twitter');
  $twitterHandleURL = $twitter_url . $twitterHandle;

  $websiteHandle = get_the_author_meta('url');

  $facebookHandle = get_the_author_meta('facebook');

  $gplusHandle = get_the_author_meta('googleplus');

  $linkedinHandle = get_the_author_meta('linkedin');

  $slideshareHandle = get_the_author_meta('slideshare');

  $payload["@type"] = "Person";
  $payload["name"] = $author_data->display_name;
  $payload["email"] = $author_data->user_email;
  $payload["sameAs"] =  array(
    $twitterHandleURL, $websiteHandle, $facebookHandle, $gplusHandle, $linkedinHandle, $slideshareHandle




Read this amazing and expanded discussion from an SEO's point of view:


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

schema.org ,search engine optimization ,wordpress ,php ,json-ld ,code snippet

Published at DZone with permission of Rodrigo Kyle Mehren, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}