• Zur Hauptnavigation springen
  • Skip to main content
  • Zur Hauptsidebar springen
  • Zur Fußzeile springen
Logo

CITROWEB Webdesign

Erste Wahl für Ihren Onlineauftritt

  • Home
  • Leistungen
    • Webdesign, Webentwicklung und Beratung
    • Online-Shops mit WooCommerce
    • Technische Unterstützung für WooCommerce-Shops
    • Suchmaschinenmarketing
      • SEO: Ihr Webauftritt erhält mehr relevante Besucher
      • SEA: Suchmaschinenwerbung für Ihren Webauftritt
    • Webhosting
  • Blog
  • Kontakt aufnehmen
Home » Blog » WooCommerce product description (full product description) as meta description in WordPress

WooCommerce product description (full product description) as meta description in WordPress

22. Dezember 2021

With the help of YOAST it is possible to display the product description as a meta description. This is done via the programmatic route as follows:

Insert the following code as a snippet in functions.php of the theme or using a plugin.

// callback für Ersetzung in YOAST SEO 
function get_fullDescription() {
    global $post;
    return $post != null ? $post->post_content : "";
}

// Registriere eigene YOAST-Variablenersetzung
function register_custom_yoast_variables() {
    wpseo_register_var_replacement( '%%fulldes%%', 'get_fullDescription', 'advanced', 'Full Description' );
}

// YOAST-Variablenersetzung bekannt machen
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');

After that, go to WordPress -> SEO -> Display in search results -> Products %%fulldes%% under Meta description. Do not forget to save!

YOAST SEO - Display in search results products
At SEO – > representation in search results -> products-> Meta description %%fulldes%% enter. YOAST replaces the variable with the variable name.

But now the complete description is used. However, it would be nicer to consider the length specification for meta descriptions of the search engines. This is a maximum of 160 characters.

For this we need two more functions. We use the replaceHtmlTags function below to replace any existing HTML tags in the description, because we don’t want them in our meta description. With the second function wordTruncate we reach the length specification. The code ensures that it is not simply separated after 160 characters and thus possibly cut off in the middle of the word, but it is cut off after the last word that is still within the 160 characters.

function replaceHtmlTags($string) {
	return preg_replace("/<.*?>/", "", $string);
}

function wordTruncate($string, $desired_max_width) {
  $parts = preg_split('/([\s\n\r]+)/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
  $parts_count = count($parts);

  $length = 0;
  $last_part = 0;
  for (; $last_part < $parts_count; ++$last_part) {
    $length += strlen($parts[$last_part]);
    if ($length > $desired_max_width) { break; }
  }

  return implode(array_slice($parts, 0, $last_part));
}

The routine get_fullDescription from the code above is modified again and looks like this:

// callback für Ersetzung in YOAST SEO 
function get_fullDescription() {
    global $post;
    return wordTruncate(replaceHtmlTags($post->post_content), 160);
}

The complete code thus looks like this:

// callback für Ersetzung in YOAST SEO 
function get_fullDescription() {
    global $post;
    return wordTruncate(replaceHtmlTags($post->post_content), 160);
}

// Registriere eigene YOAST-Variablenersetzung
function register_custom_yoast_variables() {
    wpseo_register_var_replacement( '%%fulldes%%', 'get_fullDescription', 'advanced', 'Full Description' );
}

// YOAST-Variablenersetzung bekannt machen
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');

function replaceHtmlTags($string) {
	return preg_replace("/<.*?>/", "", $string);
}

function wordTruncate($string, $desired_max_width) {
  $parts = preg_split('/([\s\n\r]+)/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
  $parts_count = count($parts);

  $length = 0;
  $last_part = 0;
  for (; $last_part < $parts_count; ++$last_part) {
    $length += strlen($parts[$last_part]);
    if ($length > $desired_max_width) { break; }
  }

  return implode(array_slice($parts, 0, $last_part));
}

Thus, without the paid YOAST SEO WooCommerce extension, we have achieved to display the product description as meta description.

WooCommerce short description as meta description

If, on the other hand, you want to use the short description as a meta description, YOAST SEO offers the function in the free version, albeit somewhat hidden.

>> In order to use the short description as a meta description we enter the variable %%wc_shortdesc%% variable.

Good luck with your SEO project!

Do you have any further questions or do you need support, I will be happy to assist you. Write me without any obligation or call me.

Contact CITROWEB

Kategorie: SEO, WooCommerce, WordPress

Haupt-Sidebar

  • How to remove dashicons in WordPress frontend?
  • How do I create a website (homepage) with ChatGPT?
  • Can I create a website (homepage) with ChatGPT?
  • iOS restrictions re: bringing up the keyboard on programmatic focus
  • iOS restrictions re: bringing up the keyboard on programmatic focus
  • Remove user listing from WP-JSON
  • Benutzerauflistung aus WP-JSON entfernen
  • What does „Video is not the main content of the page“ mean?
  • Was hat es mit „Das Video ist nicht der Hauptinhalt der Seite“ auf sich?
  • Remove WordPress logo from toolbar
  • Efficient onboarding simplified: LearnSuite – the cloud application for digital onboarding
  • Wir stellen vor: LearnSuite – Die Cloudanwendung für digitales Onboarding
  • Howto: How do I create a website (homepage) with ChatGPT?
  • Howto: Wie erstelle ich mit ChatGPT eine Website (Homepage)?
  • Can I create a website (homepage) with ChatGPT?
  • Kann ich mit ChatGPT eine Website (Homepage) erstellen?
  • Set noindex nofollow via .htaccess HTTP header
  • Über .htaccess X-Robots-Tag noindex nofollow setzen
  • How to remove WordPress Dashicons in frontend?
  • Wie lassen sich Dashicons im WordPress-Frontend entfernen?
  • DSGVO (3)
  • GDPR (3)
  • Genesis Framework (10)
  • Genesis-Framework (9)
  • Google Search Console (4)
  • Google Search Console (4)
  • Linux (3)
  • Linux (3)
  • mobile (3)
  • Mobile (3)
  • Network (1)
  • Netzwerk (1)
  • SEO (5)
  • SEO (5)
  • Trends (3)
  • Trends (4)
  • Uncategorized (3)
  • Web development (1)
  • Web hosting (1)
  • Webentwicklung (1)
  • Webhosting (1)
  • WooCommerce (9)
  • WooCommerce (9)
  • WordPress (23)
  • WordPress (24)

Footer

Logo




© 2026 CITROWEB
  • Datenschutz
  • Impressum