Skip to content

Instantly share code, notes, and snippets.

@crumina
Created October 8, 2015 07:44
Show Gist options
  • Save crumina/dbfdc8a53bfa70f6e35e to your computer and use it in GitHub Desktop.
Save crumina/dbfdc8a53bfa70f6e35e to your computer and use it in GitHub Desktop.
function crum_changed_content($num,$no_more = false)
{
global $post;
$options = get_option('second-touch');
if ($options['read_more_style'] == '0'){
$read_more_link = '<a href="'. get_permalink($post->ID) . '" class="link-read-more"> </a>';
}else{
$read_more_link = '<a href="'. get_permalink($post->ID) . '"> '.__('Read more','crum').'</a>';
}
if ($no_more == true) {
$read_more_link ='';
}
$theContent = '';
if ( has_excerpt() ) {
$theContent = get_the_excerpt();
}
if ($theContent == '') {
$theContent = get_the_content();
}
$output = preg_replace('/<img[^>]+./', '', $theContent);
$output = preg_replace('/<blockquote>.*<\/blockquote>/', '', $output);
$output = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s', '', $output);
$output = strip_tags($output);
$limit = $num + 1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ", $content);
if (strlen($content) > 0){
$content = $content . $read_more_link;
}else{
$content = '';
}
echo $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment