Wordpress: Shorten the title of posts or everything else you want
In a recent project I needed a section with short notes (common as asides) and a list of posts in the sidebar. The problem was only, that the length of the posttitle was to long for my theme and my layout suffered under this small bug. I also didnt wanted to change the wordpress core files which might be replaced by updates in future. So I wrote a solution for this and am sharing it to the public. Alle additions are only to make in your theme. Use it for everything you want, just let the note intact or link back to this site.
Now, lets get ready:
Create or open the functions.php in your wordpress templates folder. We will add a function which makes all the work for us everytime we will need it.
FIND
<?php
ADD BENEATH
// Wordpress Hack by Knowtebook.com
// Shorten any text you want
function ShortenText($text)
{
// Change to the number of characters you want to display
$chars_limit = 100;
$chars_text = strlen($text);
$text = $text." ";
$text = substr($text,0,$chars_limit);
$text = substr($text,0,strrpos($text,' '));
// If the text has more characters that your limit,
//add ... so the user knows the text is actually longer
if ($chars_text > $chars_limit)
{
$text = $text."...";
}
return $text;
}
Now we add a little code to the place within the loop for example to cut the title. It will call the function and short the title. Take attention to the title function: get_the_title() instead of the_title(), because the_title() would give out the title directly.
FIND
<?php the_title(); ?>
REPLACE WITH
<?php echo ShortenText(get_the_title()); ?>
You can use this for any text to shorten. You just have to double the function and give it a new name, so you can have different character limits.
Have fun and share!
Spread the words
Digg Del.icio.us Stumble Facebook Float Technorati BumpRelated Knowtes
Subscribe
If you liked this Knowte, why not subscribe to our RSS feed?
advertising Anti-Spam browser chat cms coding css design dhtml email fonts forms freebies google graphics hosting icons ideas inspiration iphone javascript jquery marketing mobile office pdf photos photoshop php plugins rss search engine seo stock technology templates themes tools trends tutorials usability wallpaper webhosting wordpress workflow
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 7 or better.
Subscribe to KnowTeBook
LovedKnowTes
- Community Link Feed
- Free Simple Wordpress Portfolio Theme
- 8 Free Brand Logo Download Websites You Should Know
- Pattern Freebies: 26.000+ Free Photoshop Patterns for any use
- Free Design Portfolio Theme for WordPress: ImPress
- Free Wordpress Theme for Designer and Portfolio Websites
- Graphics: 15 000 free high quality icons
- 35 Free Beautiful Japan Theme ICONS
- Cool Business Cards That People Will Never Throw Away
- Graphics: 9 Free Vector PNG Icons
- Graphics: 66 free logo vector templates for your business
- How To Create a Retro Wallpaper
- 56 Free Vector Arrow Symbols & Icons
- Free Photoshop Case Templates For DVD, CD and Cassette
- Freebies: Twitter Bird Icons & Illustration
- 34+ free HTML newsletter templates for startups
- Free vector brand logotypes in CDR, EPS and WMF formats
- Convert your Image To Vector Online For Free
- Graphics: Free Smashing Vector Icon Set - Milky
- 125 FREE Oldschool Pattern Swatches for Illustrator
- 8 Heatmap Tools and Why / How to use them
- Free Icons: Digg, Twitter, Stumble, RSS, Delicious & Reddit
- Free iPhone Design Set for Photoshop
- How To Promote Your Posts in 10 Minutes to 1 Mio People
- Clever Flickr Open Source Flash Image Gallery For Your Website
- 148 free beautiful vector graphics for web and print
- Free iPhone style Photoshop Icons
- CMS: Open source php cms without database
- Creative Online Ad Design: Ideas & Trends in 2008
- Free Unique WordPress Magazine Theme: ZinePress
- The Most Stunning Viral Ad Campaigns Ever
- Free Hand Drawn Social Media Icon Set as Vector for Bloggers
- 20 web-based business collaboration tools that lets make you breathless
- CSS: How to make a footer which really stays on the bottom
- 6 Awesome Wallpapers for PC, MAC and Iphone
- Create a realistic Credit Card in Photoshop
- What's better? Ruby on Rails vs. PHP
- PDF-Dokumente kostenlos aus Microsoft Word, Excel oder Powerpoint erstellen
- CSS Revolution - Use Condition Rules WITHIN Styles
- CODA BLUE Free WordPress Portfolio Theme
- Ambient Media Premium Advertising Inspiration
- Graphics: Great Free Icons & iphone Wallpaper at Pixelgirl
- Graphics: 2000+ Open Source Web Templates
- 25 graphic resources for ornaments, fleurons, and more
- SEO: How To Create a Google Sitemap in 5 Minutes
- Free Brilliant Website Chats and Why / How to use them
- 80 Free Mobile Device Icons Including BlackBerry Special
- Combine Wordpress, PHPBB and 4Images together without multiple user-registrations
- Von Word zu PDF kostenlos in 3 Minuten
- Free Vector Graphics at Vecteezy
- Graphics: 15 Free Outstanding Icon Sets for iPhone
- Most Awarded Advertisements in 2008
- Selected Free Wallpapers That Rock - Volume 1
- Interesting Sites
- 1.000 More Free High Quality Icons For Download
- Freebies: Creative Twitter Themes
- CSS: How To Hide Headlines For Better SEO Effects
- Self-Marketing: Outstanding Portfolio Ideas in 3D
- 100+ Free Photoshop Actions at Erics FX
- 8 Free Daily Calender Icon Set for Blogs
Community Links
- your red colored website on QNT
To complete the red color line QNT is searching for red colored websites.
- Photomanipulation by Jose Neto
José Neto, brazilian, born in Brasília-DF, raised in Goiânia, art director and photographer for fun. Worked for clients such as Citroen, Fly Emirates, and many others.
- jQuery - The easy way to navigate
15 different solutions to navigate through websites. The JavaScript-Framework “jQuery” is going to show you “how”!
- 41 websites to promote your design articles and resources | CrazyLeaf Design Blog
[…] Dzone* Dzone page Fuel Your Creativity Submit news page GoMediaZine Submit news page Knowtebook Submit news page My Ink Blog Submit news page Noupe Submit news page Pixel Groovy Submit news page Smashing Apps […]
- 150 UNIQUE and FREE Vector illustration.
Download over 150 UNIQUE vector illustrations available for download only on Grafplus.com . You will not find these vectors elsewhere.
- Creative Caricatures by Anthony Geoffroy
Amazing and funny cartoons by Anthony Geoffroy, professional illustrator, based in France. Enjoy the super creative artworks.
- Amazing Waves Photography by Clark Little
Fantastic photos by Clark Little, photographer of breaking waves . Clarks photos capture the beauty and power of monstrous Hawaiian waves from the inside out
- Photography Blog
An inspirational publication for photographers.
- How to Fix or Remove bX Errors in Blogger XML Templates
If you’re a Blogger.com user and facing these annoying errors (bX-xxxxxx) when adding new widgets or uploading a custom template, here is the solution for you.
- Beautiful Photography by Markus Klinko
French-Hungarian Markus Klinko was born in Switzerland, began piano at 3, studied harp at the Paris National Conservatory, and had an illustrious career as one of the world’s top classical harp soloists
- Crinoline Flowers by Daryl Banks
Beautiful legs in works Daryl Banks, creative and very talanted glamour photographer. Daryl is Toronto based fashion photographer. Enjoy the unusual photoworks.
- web 2.0 templatesWeb 2.0 templates with simplicity, cleanliness, and elegance in design and the less number of columns and work great for all your needs and have all the great features of Web 2.0 technology.
KnowTeBook.com
UserTalk
mktgbill: Though I imagine there are cases where it is feasible to use hidden H1 tags to replace comparable graphic...
TechSpice: In a recent project I needed a section with short notes (common as asides) and a list of posts in the...
Brenth: I have a question. On your sidebar you have a section called LovedKnowTes and under it are what appears to...
Rob Lee: Just wanted to point out that OnePress has decided to drop support for PhpBB in favor of a new bb.
Rum: I like the Ads from Absolut Vodka!
Friends
- Craig Farrall’s Blog
- Dezignus
- Flash Mint Design Blog
- Free Photoshop Brushes
- fudgegraphics
- Fuel Your Creativity
- Just Creative Design
- Logo designs
- My Ink Blog
- NaldzGraphics
- Photoshop Girl Tutorials
- Realwebmaster.net
- scripthosting.net
- spidanet.de
- Store 64
- Tasarimini | Graphic Tools
- tutorialzone.de
- Website templates
- Webtoolkit4.me

Knowtebook
Jun 26, 2009
No: 11 / ID: 4421
Hi Brenth, it is a plugin which measures the popularity of the posts according to the traffic on them.
Brenth
Jun 26, 2009
No: 10 / ID: 4420
I have a question. On your sidebar you have a section called LovedKnowTes and under it are what appears to be an archive of your posts. Is this a widget or did you hard-code it into the theme?
GenthonX
May 21, 2009
No: 9 / ID: 4299
Ups..SOLVED by myself.. there is open php tag in file functions. Thank you.
GenthonX
May 21, 2009
No: 8 / ID: 4298
Thanks for the great function. But I have problem after instal it. I can’t login to wordpress dashboard. Please help me. Thanks
kirit
May 16, 2009
No: 7 / ID: 4279
Well solution!! Works perfectly.
Thanks a lot.
Hyder
Dec 15, 2008
No: 6 / ID: 3504
Thanks for the code! Really appreciate it.
hama
Nov 26, 2008
No: 5 / ID: 3349
THANKS
3wlink
Nov 17, 2008
No: 4 / ID: 3247
Hi, I was looking for exactly this code. Thanks a lot for the nice and excellent solution.
Room 237: Origins
Oct 11, 2008
No: 3 / ID: 2835
This worked perfectly, and was exactly what I was looking for. Thank you!
TechSpice
Jun 27, 2009
ID: 2
Shorten the title of posts or everything else you want…
In a recent project I needed a section with short notes (common as asides) and a list of posts in the sidebar. The problem was only, that the length of the posttitle was to long for my theme and my layout suffered under this small bug. I also didnt wan…
Wordpress: Shorten the title of posts or everything else you want | mediaplana
Mar 25, 2008
ID: 2
[…] (more…) […]