Yoast\WP\SEO\Generators
Schema_Generator::remove_empty_breadcrumb
Removes the breadcrumb schema if empty.
Метод класса: Schema_Generator{}
Хуков нет.
Возвращает
Массив. The schema graph with empty breadcrumbs taken out.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->remove_empty_breadcrumb( $graph, $context );
- $graph(массив) (обязательный)
- The current schema graph.
- $context(Meta_Tags_Context) (обязательный)
- The meta tags context.
Код Schema_Generator::remove_empty_breadcrumb() Schema Generator::remove empty breadcrumb Yoast 26.5
protected function remove_empty_breadcrumb( $graph, $context ) {
if ( $this->helpers->current_page->is_home_static_page() || $this->helpers->current_page->is_home_posts_page() ) {
return $graph;
}
// Remove the breadcrumb piece, if it's empty.
$index_to_remove = 0;
foreach ( $graph as $key => $piece ) {
if ( \in_array( 'BreadcrumbList', $this->get_type_from_piece( $piece ), true ) ) {
if ( isset( $piece['itemListElement'] ) && \is_array( $piece['itemListElement'] ) && \count( $piece['itemListElement'] ) === 1 ) {
$index_to_remove = $key;
break;
}
}
}
// If the breadcrumb piece has been removed, we should remove its reference from the WebPage node.
if ( $index_to_remove !== 0 ) {
\array_splice( $graph, $index_to_remove, 1 );
// Get the type of the WebPage node.
$webpage_types = \is_array( $context->schema_page_type ) ? $context->schema_page_type : [ $context->schema_page_type ];
foreach ( $graph as $key => $piece ) {
if ( ! empty( \array_intersect( $webpage_types, $this->get_type_from_piece( $piece ) ) ) && isset( $piece['breadcrumb'] ) ) {
unset( $piece['breadcrumb'] );
$graph[ $key ] = $piece;
}
}
}
return $graph;
}