Last active
October 11, 2018 15:17
-
-
Save seventhqueen/69214993e3605826e6837e22a30bd04b to your computer and use it in GitHub Desktop.
Generate Schema org for the body tag on a Wordpress site
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
<html> | |
<head> | |
<title>page title</title> | |
</head> | |
<body <?php body_class(); ?> <?php kleo_schema_org_markup();?>> | |
</body> | |
</html> |
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
<?php | |
/* Schema org for body */ | |
if ( ! function_exists( 'kleo_get_schema_org_markup' ) ) { | |
function kleo_get_schema_org_markup() { | |
$schema = 'http://schema.org/'; | |
// Is woocommerce product | |
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { | |
$type = 'Product'; | |
} elseif ( is_singular( 'post' ) ) { | |
$type = "Article"; | |
} else { | |
if ( is_author() ) { | |
$type = 'ProfilePage'; | |
} // Is search results page | |
elseif ( is_search() ) { | |
$type = 'SearchResultsPage'; | |
} else { | |
$type = 'WebPage'; | |
} | |
} | |
$type = apply_filters( 'kleo_schema_org_type', $type ); | |
return 'itemscope itemtype="' . $schema . $type . '"'; | |
} | |
} | |
function kleo_schema_org_markup() { | |
echo kleo_get_schema_org_markup(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment