Skip to content

Instantly share code, notes, and snippets.

@mattbrett
Created March 14, 2014 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattbrett/9557507 to your computer and use it in GitHub Desktop.
Save mattbrett/9557507 to your computer and use it in GitHub Desktop.
Works, but always adds more button, even if there's only one paragraph.
<?php
function the_content_readmore($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content = apply_filters('the_content', $content);
$content = explode("</p>", $content);
foreach ($content as $key => $value){
if ($value != null || $value != ''){
if ( !stripos( $content[$key], '<iframe' ) === false ){
echo $content[$key];
for($i = $key+1; $i < count($content); $i++ ){
echo $content[$i];
if ($content[$i] != null || $content[$i] != '') break;
}
}
else{
for($i = $key; $i < count($content); $i++ ){
echo $content[$i];
if ($content[$i] != null || $content[$i] != '') break;
}
}
break;
}
else echo $value;
}
echo '<a href="javascript:void(0);" class="button button-more">Read More <i class="fa fa-lg fa-chevron-circle-down"></i></a>';
}
@mattbrett
Copy link
Author

This function creates a custom excerpt and tacks a "more" button on the end. The excerpt is limited to a single paragraph, or an iframe (embedded video) and a paragraph. The problem, is that the "more" button is shown at all times, even if only one paragraph exists.

@kerihenare
Copy link

Line 8. Do you intend to say "There is no iframe" OR "Doesn't start with an iframe" ?

@kerihenare
Copy link

Total rewrite but this should do what you want: https://gist.github.com/kerihenare/9557715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment