Support

Account

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;
    	}
    }