Home › Forums › General Issues › "Read more" in ACF text or wysiwyg field › Reply To: "Read more" in ACF text or wysiwyg field
I found this smart solution for functions.php:
function showBeforeMore($fullText){
if(@strpos($fullText, '<!--more-->')){
$morePos = strpos($fullText, '<!--more-->');
print substr($fullText,0,$morePos);
print "<span class=\"read-more\"><a href=\"". get_permalink() . "\" class=\"read-more-link\">Read More</a></span>";
} else {
print $fullText;
}
}
<?php showBeforeMore(get_field('YOUR-FIELD-NAME')); ?>
my goal for Wysiwyg Editor with <!–more–> was to integrate a toggle read-more/less-button:
function readmore($fullText){
if(@strpos($fullText, '<!--more-->')){
$morePos = strpos($fullText, '<!--more-->');
$fullText = preg_replace('/<!--(.|\s)*?-->/', '', $fullText);
print substr($fullText,0,$morePos);
print "<div class=\"read-more-content hide\">". substr($fullText,$morePos,-1) . "</div>";
print "<a class=\"ui lined small button read-more\">Read More</a>";
} else {
print $fullText;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.