From f5187d650aa6de0301608fe2067cc3aee92400de Mon Sep 17 00:00:00 2001 From: opportus Date: Thu, 18 Aug 2016 02:31:13 +0200 Subject: [PATCH] improved structured data - PHP<=5.4 compatibility fix plus few little tweaks --- includes/class-wc-structured-data.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-structured-data.php b/includes/class-wc-structured-data.php index ab9af0da7d5..b3514c9b759 100644 --- a/includes/class-wc-structured-data.php +++ b/includes/class-wc-structured-data.php @@ -301,22 +301,29 @@ class WC_Structured_Data { if ( ! is_array( $breadcrumb ) ) { return false; } - - if ( empty( $breadcrumb = $breadcrumb['breadcrumb'] ) ) { + + if ( isset( $breadcrumb['breadcrumb'] ) ) { + $breadcrumb = $breadcrumb['breadcrumb']; + } + + if ( empty( $breadcrumb ) ) { return; } $position = 1; - foreach ( $breadcrumb as $key => $value ) { - $markup_crumbs[] = array( + foreach ( $breadcrumb as $key => $crumb ) { + $markup_crumbs[ $key ] = array( '@type' => 'ListItem', 'position' => $position ++, 'item' => array( - '@id' => ! empty( $value[1] ) && sizeof( $breadcrumb ) !== $key + 1 ? $value[1] : '#', - 'name' => $value[0], + 'name' => $crumb[0], ), ); + + if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) { + $markup_crumbs[ $key ]['item'] += array( '@id' => $crumb[1] ); + } } $markup['@type'] = 'BreadcrumbList';