Hi! I would like to write a hook in function.php which allows me to display up to a limit of characters in the listing page. And if it’s longer than threshhold, I would like to redirect to a URL.
I am testing with this code below but it’s not working. Am I doing something wrong?
My guess is in the ‘hivepress/v1/forms/…’ part.
Thank you for your attention.
//Limit Characters
add _filter (
'hivepress/v1/forms/listing_description',
'hivepress/v1/forms/listing_CustomURL', //This is a custom attribute
function ($description, $CustomURL) {
// Check if the description has more than 250 characters
if (strlen($description) > 250) {
// Trim the description to 250 characters
$trimmed_description = substr($description, 0, 250);
// Append ellipsis (...) to indicate that the description was truncated
$trimmed_description .= '...';
$trimmed_description .= ' <a href="' . esc_url($CustomURL) . '">Read more</a>';
return $trimmed_description;
} else {
// Return the original description if it's 250 characters or less
return $description;
},
1000
}