Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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 craigedmonds/9cd974a499262f088eef3272925ca972 to your computer and use it in GitHub Desktop.
Save craigedmonds/9cd974a499262f088eef3272925ca972 to your computer and use it in GitHub Desktop.
Wordpress Get First X Chars From Post
<?php
#########################################################
// Get the first X chars from the content post (strips out any html)
// USAGE: get_intro_text($max_char = 75, $content, $more_link_text = '(more...)')
#########################################################
function get_intro_text($max_char, $content, $more_link_text = '(more...)') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = strip_tags($content);
if (strlen($_GET['p']) > 0) {
return $content;
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
return $content . "...";
}
else {
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment