Skip to content

Instantly share code, notes, and snippets.

@teles
Created September 28, 2016 16:47
Show Gist options
  • Save teles/acfb8701cfe30b541f259df938dd48e8 to your computer and use it in GitHub Desktop.
Save teles/acfb8701cfe30b541f259df938dd48e8 to your computer and use it in GitHub Desktop.
<?php
if (is_single()) {
function get_post_data() {
global $post; return $post;
}
$json_metadata["@context"] = "http://schema.org/";
$post_data = get_post_data();
$category = get_the_category();
$post_thumbnail = get_the_post_thumbnail($post->ID);
preg_match_all("/(width|height)=\"([0-9]*)\"/", $post_thumbnail, $thumbnail_sizes);
$post_thumbnail_width = ($thumbnail_sizes[2][0]);
$post_thumbnail_height = ($thumbnail_sizes[2][1]);
$author_data = get_userdata($post_data->post_author);
$post_url = get_permalink();
$post_thumbnail_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
$json_metadata["@type"] = "BlogPosting";
$json_metadata["url"] = $post_url;
$json_metadata["author"] = array( "@type" => "Person", "name" => $author_data->display_name);
$json_metadata["headline"] = $post_data->post_title;
$json_metadata["datePublished"] = $post_data->post_date;
$json_metadata["dateModified"] = $post_data->post_modified;
$json_metadata["image"] = array("@type"=> "ImageObject", "url" => $post_thumbnail_url, "width" => $post_thumbnail_width, "height" => $post_thumbnail_height);
$json_metadata["Publisher"] = array("@type" => "Organization", "name" => "Viva Decora");
$json_metadata["mainEntityOfPage"] = get_permalink();
$json_metadata["articleBody"] = $post_data->post_content;
$json_metadata["Publisher"]["logo"] = array("@type" => "ImageObject", "url" => "https://cdn.vivadecora.com.br/static/img/logo-vivadecora.png", "width" => "199", "height" => "40");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment