Created
June 19, 2016 16:01
-
-
Save ahmedkaludi/9fde46eb07c5bd7e14bece48ace4b8e5 to your computer and use it in GitHub Desktop.
Structured Data in WordPress
This file contains hidden or 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() ) { | |
$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
i am facing this problem in google search console Error Type Missing: name 1 Items with Error, more important thing i dont know how and where to go so as to resolve this issue i acknowledged what is the error actually by testing live. but dont know how can i resolve this in wordpress.http://archeoskins.com/
