Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.