Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Last active August 29, 2015 13:56
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 certainlyakey/9323610 to your computer and use it in GitHub Desktop.
Save certainlyakey/9323610 to your computer and use it in GitHub Desktop.
Wordpress - custom content function with manual word limit
//Custom content function with words manual limit
function content($limit, $postid, $showmorelink = true) { //Normally, the second parameter provided is '$post->ID'
$content = explode(' ', get_post_field('post_content', $postid), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content);
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'<br />');
$content .= '&hellip;';
if ($showmorelink) {$content .= ' <a class="more-link" href="'. get_permalink($postid) . '">Читать далее...</a>';}
} else {
$content = implode(" ",$content);
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment