Der obs_structured_data_before_breadcrumbs
Filter filtert die Ausgabe der Schema.org Daten für die Breadcrumbs, die auf Produkt -und Kategorieseiten erstellt werden.
Die Schema.org Daten werden als JSON-LD im Header ausgeliefert, siehe Breadcrumb Blöcke für Produkt Templates und Kategorie Templates.
Dieser Filter läuft, bevor die HTML-Representation erstellt wird. Der Filter kann genutzt werden, um
- die Parameter, die der Standard-Funktion übergeben werden, zu verändern bevor das Standard-Design angewendet wird
(dazu null returnen, der erste Parameter ist null) - die Darstellung der strukturierten Daten selbst zu erstellen
(dazu die neue Darstellung als String returnen)
Beispiel-Anwendung über functions.php in Child-Theme
Verändern der Parameter, Standard-Design:
add_filter( 'obs_structured_data_before_breadcrumbs', 'custom_structured_data_before_breadcrumbs', 10, 3 );
function custom_structured_data_before_breadcrumbs( $structured_data_before_breadcrumbs, $class, &$explore_path ) {
// TODO: change the $class or the $explore_path.
return $structured_data_before_breadcrumbs;
}
Eigenes Design:
add_filter( 'obs_structured_data_before_breadcrumbs', 'custom_structured_data_before_breadcrumbs', 10, 3 );
function custom_structured_data_before_breadcrumbs( $structured_data_before_breadcrumbs, $class, &$explore_path ) {
// TODO: change the $structured_data_before_breadcrumbs content.
return $structured_data_before_breadcrumbs;
}
Anleitung zur Integration von Hooks
Eine Integration im Code
/**
* Filter the structured data for breadcrumbs on both Category Pages and Product Pages before creation.
*
* Return null to use the default build-up.
* Otherwise, the default will be skipped and the returned content (array) given back as structured data.
*
* Call the $explore_path by reference when attempting to edit it before applying standard design.
*
* @param array|null $structured_data_breadcrumbs Return an array to use as breadcrumb structured data or return null to use the default.
* @param string $class The class of the Caller. Either Oneboxshop_Category_Page or Oneboxshop_Product_Page.
* @param array $explore_path The explore_path array holding the product(s) data.
*/
$structured_data_breadcrumbs = apply_filters_ref_array(
'obs_structured_data_before_breadcrumbs',
array(
null,
$class,
&$this->explore_path,
)
);