Der obs_structured_data_product_minimum_check
Filter filtert die Ausgabe der Schema.org Daten für die Produkte, die auf Produkt -und Kategorieseiten erstellt werden.
Die Schema.org Daten werden als JSON-LD im Header ausgeliefert.
Dieser Filter läuft, nachdem die HTML-Representation erstellt wurde und bevor sie ausgegeben wird. Er läuft nur, wenn für das Produkt mindestens eine der fünf von Google als notwendig markierten Eigenschaften nicht vorliegen:
- Produktbild (immer gegeben, notfalls Standardbild)
- Produktname (immer gegeben)
- Verfügbarkeit
- Preis
- Währung
Standardmäßig wird dieses Produkt dann nicht zu den strukturierten Daten hinzugefügt. Wenn ein Produkt trotzdem als strukturierte Daten ausgegeben werden soll, kann dieser Filter verwendet werden.
Beispiel-Anwendung über functions.php in Child-Theme
add_filter( 'obs_structured_data_product_minimum_check', 'custom_structured_data_product_minimum_check', 10, 3 );
function custom_structured_data_product_minimum_check( $new_structured_data_product, $class, $structured_data_product) {
// TODO: change the $new_structured_data_product array.
return $new_structured_data_product;
}
Anleitung zur Integration von Hooks
Eine Integration im Code
/**
* Filter the output, if the minimum check failed. If availability, price or priceCurrency are not set,
* $structured_data_product is set empty. Filter to change
*
* @param array $structured_data_product_after The empty structured data for the product, after filtering.
* @param string $class Name of the class: Either Oneboxshop_Category_Page or Oneboxshop_Product_Page.
* @param array $structured_data_product_before The structured data for the product, with (incomplete) data.
*/
$structured_data_product = apply_filters_ref_array(
'obs_structured_data_product_minimum_check',
array(
array(),
$class,
$structured_data_product,
)
);