745305
You probably have your situation figured out but I am posting this
for anyone else that might look at this post.
If wordpress already has a function like this and anyone has found
it, please let me know.
I modified a version of code taken from
http://www.totallyphp.co.uk/code/shorten_a_text_string.htm
“This will also round the text to the nearest whole word instead
of cutting off part way through a word.”
I added the strip_tags function because when I used shorten_text(),
it would cut the string half way through a html tag which leaves
an open html tag when the page is rendered. (left the <p> tags in)
This is a simplified version of what I have so hopefully it works.
function shorten_text($text, $chars) {
$text = strip_tags($text, '<p>');
$text = trim($text);
if(!$text){
return;
}
else{
if(!chars){
echo $text;
}
elseif($chars){
$text = $text." ";
$text = substr($text,0,$chars);
$text = $text."...";
echo $text;
}
else{
return;
}
}
}
(@rori)
16 years ago
Hi, I have found the code for the recent comments widget in the widgets.php file.
What I would like to be able to do is change this code so that it will truncate the number of characters output for “comment author’s” name. I have a lot of comments and lately, they are doing silly things like using names like “mindy in a bedazzled hot pink leather jacket in new jersey” as their comment author name and it is WACK.
So, here is the code I need help with.
I will buy you a nice beverage if you help. 🙂