I am trying to pull content from an ACF (Advanced Custom Field) value and trim it by character count. I want to append the truncated string with a 'Read More' text that uses an href value from another ACF field.
<?php
$content = get_field('app_description');
//^get $content from ACF field, no problem
echo mb_strimwidth($content, 0, 306, "... <a class=\"f-size14 external\" href=\"' . get_field('app_link') . '\">Read More</a>");
?>
When I do this, it appears correct until you click on the "Read More" link. It outputs "https://demosite.com/page/%20.%20get_field(app_link"
How can I trim a field to a character count, and use another value / variable for the href?
I have also tried adding this to my functions.php
function get_prod_desc( $count, $rmtext ) {
$link = get_field('app_link');
$excerpt = get_field('app_description');
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = '<p>'.$excerpt.'... <a href="'.$link.'" class="f-size14 external">'. $rmtext .'</a></p>';
return $excerpt;
}
and calling it in my template like this
echo get_prod_desc(300, 'view more');
The results are very inconsistent in terms of actual character count, and it adds the 'view more' to content blocks under 300.