I want to get the long description of the WooCommerce product to display it in the head…
The following code works fine for the product short description:
<head>
<meta name="description" content="<?php
$excerpt = '';
if (has_excerpt()) {
$excerpt = wp_strip_all_tags(get_the_excerpt());
echo $excerpt;
}
?>"/>
</head>
But I want the long description to be displayed instead, so I made some changes to the code:
<head>
<meta name="description" content="<?php
$description = '';
if (has_description()) {
$description = wp_strip_all_tags(get_the_description());
echo $description;
}
?>"/>
</head>
Unfortunately, it doesn't work at all.
How to display WooCommerce product long description in the head?
The functions has_description()
and get_the_description()
doesn't exist in WordPress neither in WooCommerce.
The correct WordPress function to be used is get_the_content()
like:
<head>
<meta name="description" content="<?php
$description = get_the_content();
if ( $description) {
echo wp_strip_all_tags($description);
}
?>"/>
</head>
It should work.