Skip to content

Instantly share code, notes, and snippets.

@kerihenare
Forked from mattbrett/auto-read-more.php
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerihenare/9557715 to your computer and use it in GitHub Desktop.
Save kerihenare/9557715 to your computer and use it in GitHub Desktop.
<?php
/**
*
* @param string $moreLinkText
* @param integer $stripteaser
*/
function the_content_readmore($moreLinkText = null, $stripteaser = 0)
{
$content = apply_filters('the_content', get_the_content($moreLinkText, $stripteaser));
$paragraphs = explode('</p>', $content);
// If there's only one paragraph, echo the content and return
if (2 === count($paragraphs)) {
echo $content;
return;
}
// Always echo first paragraph
echo $paragraphs[0] . '</p>';
// If the first paragraph has an iframe, also echo second paragraph
if (false !== stripos($paragraphs[0], '<iframe')) {
echo $paragraphs[1] . '</p>';
}
echo '<a href="javascript:void(0);" class="button button-more">Read More <i class="fa fa-lg fa-chevron-circle-down"></i></a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment