Help with "the_title" in WordPress pls
-
Hey guys, I’ve been trying to get my post titles truncated because some of the titles pulled in from Amazon are of a ridiculous length & would very often prevent that post from being submitted to the likes of Twitter.
The code I used;//function to call and print shortened post title function the_title_shorten($len,$rep='...') { $title = the_title('','',false); $shortened_title = textLimit($title, $len, $rep); print $shortened_title; } //shorten without cutting full words (Thank You Serzh 'https://us2.php.net/manual/en/function.substr.php#83585') function textLimit($string, $length, $replacer) { if(strlen($string) > $length) return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer; return $string; }
This code works fine as far as displaying
the_title
on the screen, but unfortunately it does not updatethe_title
to the truncated version, which is really what I need it to do for the reason mentioned above.
I’d very grateful if anyone can offer some advice on how to acheive this..?Thanks Steve
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Help with "the_title" in WordPress pls’ is closed to new replies.