How To Make Custom Trim Title in Wordpress
Last Updated on Wednesday, 22 July 2009 06:51 Written by Ray Friday, 10 July 2009 01:28
Some of wordpress theme developer might want to make a custom trim title. So what is it ? well maybe you can see at Anime-Zone.NET blog post where in the sidebar, you’ll see some post will be trimmed and added “…” at the end of the title. If that’s what you wanted to make, here’s how:
- open your theme’s function file (function.php) or create one if you haven’t
- Add these codes:
function custom_trim_title($title_len) { global $post; $trunc_ex = substr($post->post_title, 0, $title_len); //truncate excerpt to fit remaining space if(strlen($trunc_ex) < strlen($post->post_title)) $trunc_ex = $trunc_ex . " ..."; return $trunc_ex; //display excerpt }
- To call the function, simply put custom_trim_title(length); on your desired position in your theme’s file. While “length” is the number of letters to be showed before “…” come out.
ok, now a it discussion about this function. this function will get the actual title
$post->post_title
and truncate it. It will then compare the length of trimmed title with actual title. If the length of the truncated title is less than the actual title then it wil add “…” at the end and use the truncated one. Otherwise it will use the actual non-trimmed title.
Screenshot
Hello, great blog you got here.
Very interesting and I like it!
If you want you can visit this blog that I just found,its new and I like reading new blogs.
You might find it Interesting like I found yours.
the url is TheSoundOfVintage.blogspot.com