Files
2026-03-05 13:07:40 +01:00

159 lines
3.9 KiB
PHP

<?php
/**
* Helper | Schema MarkUp for better SEO
*
* @package Dotspice
* @version 1.3.0
*/
/**
* Get schema markup
*
* @param string Type of the element
* @return string HTML Attribute
*/
function dotspice_schema( $type, $output = true ) {
if ( empty( $type ) ) return;
$attributes = '';
$attr = array();
switch ( $type ) {
case 'body':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/WebPage' );
break;
case 'header':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/WPHeader' );
break;
case 'nav':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/SiteNavigationElement' );
break;
case 'title':
$attr['itemprop'] = 'headline';
break;
case 'sidebar':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/WPSideBar' );
break;
case 'footer':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/WPFooter' );
break;
case 'main':
$attr['itemprop'] = 'mainContentOfPage';
if ( is_search() ) {
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/SearchResultsPage' );
}
break;
case 'author':
$attr['itemprop'] = 'author';
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/Person' );
break;
case 'person':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/Person' );
break;
case 'comment':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/UserComments' );
break;
case 'comment_author':
$attr['itemprop'] = 'creator';
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/Person' );
break;
case 'comment_author_link':
$attr['itemprop'] = 'creator';
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/Person' );
$attr['rel'] = 'external nofollow';
break;
case 'comment_time':
$attr['itemprop'] = 'commentTime';
$attr['itemscope'] = 'itemscope';
$attr['datetime'] = get_comment_date() . ' at ' .get_comment_time();
break;
case 'comment_text':
$attr['itemprop'] = 'commentText';
break;
case 'video':
$attr['itemprop'] = 'video';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/VideoObject' );
break;
case 'audio':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/AudioObject' );
break;
case 'blog':
$attr['itemscope'] = 'itemscope';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/Blog' );
break;
case 'address':
$attr['itemscope'] = '';
$attr['itemtype'] = esc_url( 'http' . dotspice_theme_ssl() . '://schema.org/PostalAddress' );
$attr['itemprop'] = 'address';
break;
case 'name':
$attr['itemprop'] = 'name';
break;
case 'url':
$attr['itemprop'] = 'url';
break;
case 'email':
$attr['itemprop'] = 'email';
break;
case 'job':
$attr['itemprop'] = 'jobTitle';
break;
case 'post_time':
$attr['itemprop'] = 'datePublished';
$attr['datetime'] = get_the_time( 'd F' );
break;
case 'post_content':
$attr['itemprop'] = 'text';
break;
}
if ( is_array( $attr ) && count( $attr ) > 0 ) {
foreach ( $attr as $key => $value ) {
if ( $output ) {
echo esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
}
else {
$attributes .= esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
}
}
}
if ( ! $output ) {
return $attributes;
}
}