Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created May 8, 2019 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/3fa585595cc27fc2a943049da5955a69 to your computer and use it in GitHub Desktop.
Save braddalton/3fa585595cc27fc2a943049da5955a69 to your computer and use it in GitHub Desktop.
Yoast SEO Genesis https://wp.me/p1lTu0-ith
add_filter( 'genesis_attr_breadcrumb', 'genesis_attributes_breadcrumb' );
/**
* Add attributes for breadcrumbs wrapper.
*
* @since 2.2.0
*
* @param array $attributes Existing attributes for breadcrumbs wrapper element.
* @return array Amended attributes for breadcrumbs wrapper element.
*/
function genesis_attributes_breadcrumb( $attributes ) {
// Homepage breadcrumb content contains no links, so no schema.org attributes are needed.
if ( is_home() ) {
return $attributes;
}
// Omit attributes if generic breadcrumb functions are in use.
if ( function_exists( 'breadcrumbs' ) || function_exists( 'crumbs' ) ) {
return $attributes;
}
// Breadcrumb NavXT plugin needs RDFa attributes on the breadcrumb wrapper.
if ( function_exists( 'bcn_display' ) ) {
$attributes['typeof'] = 'BreadcrumbList';
$attributes['vocab'] = 'https://schema.org/';
return $attributes;
}
// Yoast SEO uses JSON-LD and Yoast Breadcrumbs emits no schema.org markup, so no attributes needed.
$yoast_seo_breadcrumbs_enabled = class_exists( 'WPSEO_Breadcrumbs' ) && genesis_get_option( 'breadcrumbs-enable', 'wpseo_titles' );
$yoast_breadcrumbs_plugin_enabled = function_exists( 'yoast_breadcrumb' ) && ! class_exists( 'WPSEO_Breadcrumbs' );
if ( $yoast_seo_breadcrumbs_enabled || $yoast_breadcrumbs_plugin_enabled ) {
return $attributes;
}
// Genesis breadcrumbs require microdata on the wrapper.
$attributes['itemprop'] = 'breadcrumb';
$attributes['itemscope'] = true;
$attributes['itemtype'] = 'https://schema.org/BreadcrumbList';
if ( is_singular( 'post' ) || is_archive() || is_home() || is_page_template( 'page_blog.php' ) ) {
unset( $attributes['itemprop'] );
}
return $attributes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment