Der obs_open_graph_data
Filter filtert die Ausgabe der Open Graph Daten og:type, og:image, og:url auf Produktseiten, og:url auf Kategorieseiten. Wenn das Yoast SEO Plugin verwendet wird, der entsprechenden für Yoast SEO.
Weitere Daten können dem Array hinzugefügt werden, um auch ausgegeben zu werden.
Wichtig: Open Graph Title und Open Graph Description werden an anderer Stelle ausgegeben und haben eigene Filter, diese dürfen nicht hier mit ausgegeben werden, sonst sind sie doppelt auf der Seite!
Dieser Filter läuft, wenn der Header einer Produkt -oder Kategorieseite erstellt wird.
Der Filter ist ab OBS Pages Version 1.8 verfügbar.
Beispiel-Anwendung über functions.php in Child-Theme
/**
* Filter the open graph data to add to the page
* og:title and og:description are output at a different place
* Return empty array to not output any open graph data besides title and description
*
* @param array $open_graph_entries The array holding the open graph output. Array key is the property name, the corresponding value is the content value.
* @param array $explore_path The explore_path array holding a lot of information about the current page.
*/
function obs_adjust_og_data( array $open_graph_entries, array $explore_path ): array {
// TODO: get the og data for the given path.
$og_data = obs_get_og_data( $explore_path );
if ( ! empty( $og_data ) ) {
$open_graph_entries = $og_data;
}
return $open_graph_entries;
}
add_filter( 'obs_open_graph_data', 'obs_adjust_og_data', 10, 2 );
Anleitung zur Integration von Hooks
Eine Integration im Code
/**
* Filter the open graph data to add to the page
* og:title and og:description are output at a different place
* Return empty array to not output any open graph data besides title and description
*
* @param array $open_graph_entries The array holding the open graph output. Array key is the property name, the corresponding value is the content value.
* @param array $explore_path The explore_path array holding a lot of information about the current page.
*
* @see add_meta_title() Place to add and change the og:title.
* @see add_meta_description() Place to add and change the og:description.
*/
$open_graph_entries = apply_filters( 'obs_open_graph_data', $open_graph_entries, $this->explore_path );