Created
July 9, 2016 13:19
-
-
Save ahmedkaludi/84230ace176edde883aba9db38c6f931 to your computer and use it in GitHub Desktop.
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
// Display Tag code | |
function ahmedkaludi_structured_data_keyword() { | |
if ( is_single() | is_page() ) { | |
$tags = '"keywords" : [' . strip_tags(get_the_tag_list('"','", "','"')) . ']'; | |
} else { } | |
echo $tags; | |
} | |
function ahmedkaludi_structured_data_output() { | |
if ( is_single() ) { | |
$article_author_name = get_the_author_meta( 'nickname', $author_id ); | |
$article_published_date = get_the_time('c'); | |
$thumb_id = get_post_thumbnail_id(); | |
$thumb_url = wp_get_attachment_image_src($thumb_id,'large', true); | |
?> | |
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org", | |
"@type": "Article", | |
"headline": "<?php the_title(); ?>", | |
"image": { | |
"@type": "ImageObject", | |
"url": "<?php echo $thumb_url[0]; ?>", | |
"width": 1024, | |
"height": 1024 | |
}, | |
<?php | |
if(function_exists('ahmedkaludi_structured_data_keyword')) | |
{ | |
ahmedkaludi_structured_data_keyword(); | |
}; | |
?>, | |
"datePublished": "<?php echo $article_published_date ?>", | |
"dateModified": "<?php echo $article_published_date ?>", | |
"articleSection": "<?php $categories = get_the_category(); foreach($categories as $category) { $cat_name = $category->name; echo $cat_name ; } ?>", | |
"publisher":{ | |
"@type": "Organization", | |
"name": "<?php echo $article_author_name ?>", | |
"logo": { | |
"@type": "ImageObject", | |
"url": "http://ahmedkaludi.com/logo.jpg", | |
"width": 600, | |
"height": 60 | |
} | |
}, | |
"author": { | |
"@type": "Person", | |
"name": "<?php echo $article_author_name ?>" | |
}, | |
"articleBody": "<?php $excerpt = strip_tags(get_the_excerpt()); echo $excerpt; ?>", | |
"mainEntityOfPage": "True" | |
} | |
</script> | |
<?php } | |
} | |
add_action('wp_footer','ahmedkaludi_structured_data_output'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment