Created
August 21, 2019 13:43
-
-
Save craigedmonds/9cd974a499262f088eef3272925ca972 to your computer and use it in GitHub Desktop.
Wordpress Get First X Chars From Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(']]>', ']]>', $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