Home » Hooks » SEO: Meta Description anpassen

SEO: Meta Description anpassen

Inhalt

Der obs_meta_description Filter filtert die Ausgabe de SEO Description auf Produkt -und Kategorieseiten. Wenn das Yoast SEO Plugin verwendet wird, auch die SEO Description für Yoast SEO.

Dieser Filter läuft, wenn der Header einer Produkt -oder Kategorieseite erstellt wird.

Der Filter ist ab OBS Pages Version 1.7.3 verfügbar. Ab Version 1.9 ist der dritte Parameter $explore_path dazu gekommen.

Beispiel-Anwendung über functions.php in Child-Theme

/**
 * Adjust the SEO description of certain product or category page
 *
 * @param string $description  The already set description.
 * @param string $path         The path of the current OBS page.
 * @param array  $explore_path The explore_path array holding lots of info about the current page.
 *
 * @return string The new to set description.
 */
function obs_adjust_seo_description( string $description, string $path, array $explore_path ): string {
	// TODO: get the SEO description for the given path.
	$seo_description = obs_get_seo_description( $path );
	if ( null !== $seo_description ) {
		$description = $seo_description;
	}

	return $description;
}

add_filter( 'obs_meta_description', 'obs_adjust_seo_description', 10, 3 );

Für die Integration mittels einer JSON-Datei um für mehrere Pfade SEO Texte vorzugeben existiert auch ein Beispiel.

Anleitung zur Integration von Hooks

Eine Integration im Code

/**
 * Filter the description of the category page / product page before outputting / forwarding to Yoast
 *
 * @param string $description  The description from Elastic.
 * @param string $current_path The path of the called category / product page.
 * @param array  $explore_path The explore_path array holding lots of info about the current page.
 */
$description = apply_filters( 'obs_meta_description', $description, Oneboxshop_Pages_Functions::get_url_path(), $this->explore_path );

Hilfecenter: