Last active
January 29, 2016 12:06
-
-
Save ximosa/3db2212718e5cdb88840 to your computer and use it in GitHub Desktop.
Agregar el marcado (JSON-LD) ,estructurado en schema.org.-http://www.webgae.com/agregar-el-marcado-json-ld-estructurado-en-schema-org/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_post_data() { | |
global $post; | |
return $post; | |
} | |
// para cualquier página | |
$payload["@context"] = "http://schema.org/"; | |
// esto tiene todos los datos del post / página etc. | |
$post_data = get_post_data(); | |
// cosas para cualquier página, si es que existe | |
$category = get_the_category(); | |
// cosas para páginas específicas | |
if (is_single()) { | |
// esto se pone los datos del usuario que escribió ese artículo particular | |
$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["ArticleSection"] = $category[0]->cat_name; | |
$payload["headline"] = $post_data->post_title; | |
$payload["datePublished"] = $post_data->post_date; | |
$payload["dateModified"] = $post_data->post_date; | |
$payload["image"] = array( | |
"@type" => "ImageObject", | |
"url" => $post_thumb, | |
"width" => "600", | |
"height" => "400", | |
); | |
$payload["Publisher"] = "Webgae"; | |
$payload["mainEntityOfPage"] = "WebPage"; | |
} | |
//todo esto lo hacemos por separado por lo que mantenemos las cosas correctas para la organización en conjunto ,Cambiar con tus datos | |
if (is_front_page()) { | |
$payload["@type"] = "Organization"; | |
$payload["name"] = "Webgae"; | |
$payload["logo"] = "http://www.webgae.com/wp-content/uploads/2016/01/Logo-512x602-medium.png"; | |
$payload["url"] = "http://webgae.com/"; | |
$payload["sameAs"] = array( | |
"https://twitter.com/Webgae", | |
"https://www.facebook.com/Webgae-823685637646565/?ref=hl", | |
"https://github.com/ximosa", | |
"https://plus.google.com/+Webgae" | |
); | |
$payload["contactPoint"] = array( | |
array( | |
"@type" => "ContactPoint", | |
"telephone" => "+34667590554", | |
"email" => "info@webgae.com", | |
"contactType" => "sales" | |
) | |
); | |
} | |
if (is_author()) { | |
// esto se pone los datos del usuario que escribió ese artículo particular | |
$author_data = get_userdata($post_data->post_author); | |
// Algunos de ustedes pueden no tener todos estos puntos de datos en sus perfiles de usuario - táchese lo que no proceda | |
// Se ha podido recuperar de twitter del autor meta y concatenar con twitter URL completa | |
$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('github'); | |
$payload["@type"] = "Person"; | |
$payload["name"] = $author_data->display_name; | |
$payload["email"] = $author_data->user_email; | |
$payload["sameAs"] = array( | |
$twitterHandleURL, $websiteHandle, $facebookHandle, $gplusHandle, $linkedinHandle, $slideshareHandle | |
); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// añadir en el header.php antes de cerrar el head; | |
<?php include('json-ld.php'); ?> | |
<script type="application/ld+json"><?php echo json_encode($payload); ?></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment