How to Bold First Few Words in Excerpt
10th Apr 2011 | Posted by reza | 4 CommentsThe WordPress Excerpt is an optional summary or description of a post; in short, a post summary. It is used to truncate blog posts so that only part of the entry — the introduction or a summary of the post — is displayed, instead of the entire entry.
In my recent project, I need to bold first few words in excerpt. I’ll share the solution here.
Simply put the codes below to your theme’s function.php file
function excerpt_bold($text) { $text = explode(' ',get_the_excerpt()); $text[0]='<strong>'.$text[0]; $text[4]=$text[4].'</strong>'; $text = implode(' ',$text); return $text; } add_filter ('the_excerpt', 'excerpt_bold');
This code will bold first five words. You can change it to other number by replacing ’4′ in the code. But remember, the number should be number of bolded words reduced by one. If You want to bold 8 words, for example, then replace it with 7.
Hope this code snippet helps.
Credit :
Thanks to Alchymith and itsalltech1 at WordPress.org
1 Comment to “How to Bold First Few Words in Excerpt”
Add Comments (+)Trackbacks/Pingbacks
- 45 Best WordPress Tips and Tutorials of April 2011 | Moshkila.com
- 45 Best WordPress Tips and Tutorials of April 2011 « Moshkila.com
- 55 Best WordPress Tricks And Hacks | stylishwebdesigner
Sorry to bother you, I saw your post on how to group posts by Author and Alphabetically, but I was wondering how I could group them by Date.