Skip to content

Instantly share code, notes, and snippets.

@seventhqueen
Last active October 11, 2018 15:17
Show Gist options
  • Save seventhqueen/69214993e3605826e6837e22a30bd04b to your computer and use it in GitHub Desktop.
Save seventhqueen/69214993e3605826e6837e22a30bd04b to your computer and use it in GitHub Desktop.
Generate Schema org for the body tag on a Wordpress site
<html>
<head>
<title>page title</title>
</head>
<body <?php body_class(); ?> <?php kleo_schema_org_markup();?>>
</body>
</html>
<?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