Australian Shopping Sites Revised Adobe creative software Industry-leading CS6 master collection pixel-perfect Adobe InDesign CS6 software Interactive photo software

How to Bold First Few Words in Excerpt

The 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 (+)

  1. Tosh says:

    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.

Trackbacks/Pingbacks

  1. 45 Best WordPress Tips and Tutorials of April 2011 | Moshkila.com
  2. 45 Best WordPress Tips and Tutorials of April 2011 « Moshkila.com
  3. 55 Best WordPress Tricks And Hacks | stylishwebdesigner

Leave a Reply

 
wordpress web hosting

GreenGeeks WordPress Hosting is the most reliable wordpress web hosting provider for your blog and is 300% green.

Myshopping
facebook twitter Gfeedburner Ffeedburner

Premium Themes

Amazingly Beautiful WordPress Themes