Skip to content

Instantly share code, notes, and snippets.

@nixonmedia
Created March 29, 2018 12:56
Show Gist options
  • Save nixonmedia/df1fbfd60a02b82c352a6048f3781e70 to your computer and use it in GitHub Desktop.
Save nixonmedia/df1fbfd60a02b82c352a6048f3781e70 to your computer and use it in GitHub Desktop.
function showBeforeMore($fullText){
$more = '<!--more-->';
if(strpos($fullText, $more)!==false){
$morePos = strpos($fullText, $more);
$rest = str_replace($more, '', $morePos);
//only show the text before the <!--more-->
print substr($fullText,0,$morePos);
//add a Read More anchor
print '<a href="#" class="read_more">Continue Reading <i class="far fa-angle-down"></i></a>';
//wrap the rest of the content after the <!--more--> in a hidden class
echo '<div class="hide_content">';
$index = strpos($fullText, $more) + strlen($more);
echo substr($fullText, $index);
echo '</div><!--/hide-->';
} else {
print $fullText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment