Add Dynamic JSON-LD Schema Markup on Head

Add dynamic JSON-LD Schema Markup on Head. Given code show post name , id and URL. If you have any extra dynamic code for schema markup so connect with us.

How to add JSON-LD Schema Markup

Easily add JSON-LD Schema Markup on head without using any type of plugins and make your post for rich snippets.

<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Article",
"@id": "<?php echo "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>",
"headline": "<?php if (function_exists('is_tag') && is_tag()) { echo 'Tag Archive for "'.$tag.'" - '; } elseif (is_archive()) { wp_title(''); echo ' Archive - '; } elseif (is_search()) { echo 'Search for "'.wp_specialchars($s).'" - '; } elseif (!(is_404()) && (is_single()) || (is_page())) { wp_title(''); echo ' - '; }bloginfo('name'); ?>",
"url":"<?php echo "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>"
}
</script>

Try another code

<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "<?php if ( (is_single()) || (is_page())) {
echo "Article";} else {
echo "CreativeWork";}?>",
"@id": "<?php if ( (is_single()) || (is_page())) {
the_permalink();} else {
echo get_site_url();}?>",
"headline": "<?php if ( (is_single()) || (is_page())) {
the_title();} else {
bloginfo('name');}?>",
"description": "<?php if ( (is_single()) || (is_page())) {
$excerpt = get_the_excerpt();
$excerpt = substr( $excerpt , 0, 100);
echo $excerpt;} else {
echo "Find all type of information like technical, educational, ayurvedica or more with thekroyaard";}?>"
}
</script>

Try this one

<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@graph":[{"@type":"Organization","@id":"<?php echo get_site_url(); echo '/#organization';?>","name":"<?php bloginfo('name'); ?>"},{"@type":"WebSite","@id":"<?php echo get_site_url(); echo '/#website';?>","url":"<?php echo get_site_url(); ?>","name":"<?php bloginfo('name'); ?>","publisher":{"@id":"<?php echo get_site_url(); echo '/#organization';?>"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"<?php the_permalink(); echo '/#webpage'; ?>","url":"<?php the_permalink(); ?>","name":"<?php the_title(); ?>","datePublished":"<?php echo get_the_date( 'Y-m-d\TH:i:s'); ?>","dateModified":"<?php the_modified_date('Y-m-d\TH:i:s'); ?>","isPartOf":{"@id":"<?php echo get_site_url(); echo '/#website';?>"}},{"@type":"Article","headline":"<?php the_title(); ?>","datePublished":"<?php echo get_the_date('Y-m-d\TH:i:s'); ?>","dateModified":"<?php the_modified_date('Y-m-d\TH:i:s'); ?>","publisher":{"@id":"<?php echo get_site_url(); echo '/#organization';?>"},"description":"<?php $excerpt = get_the_excerpt();$excerpt = substr( $excerpt , 0, 200);echo $excerpt;?>","name":"<?php the_title();?>","@id":"<?php echo the_permalink(); echo '/#richSnippet';?>","isPartOf":{"@id":"<?php echo the_permalink(); echo '/#webpage';?>"},"mainEntityOfPage":{"@id":"<?php echo the_permalink(); echo '/#webpage';?>"}}]}
</script>

Paste this code between <head> then SAVE.