Title: Adding Span to Title
Last modified: August 20, 2016

---

# Adding Span to Title

 *  [swellness](https://wordpress.org/support/users/swellness/)
 * (@swellness)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/adding-span-to-title/)
 * Hello,
    I need to know how to add a span tag to a post title. What I need to 
   accomplish is to have the first word of each title be a different color then 
   the remaining words. I know it’s possible as it is accomplished on this blog.
 * [http://harvesthealth5k.com/?page_id=164](http://harvesthealth5k.com/?page_id=164)
 * Could anyone help me? I would very much appreciate it.
 * modifying

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/adding-span-to-title/#post-2318816)
 * for just the page title, edit page.php and replace `the_title();` with:
 *     ```
       $words = explode(' ', the_title('', '',  false));
       $words[0] = '<span>'.$words[0].'</span>';
       $title = implode(' ', $words);
       echo $title;
       ```
   
 * —-
    or for generally all titles (this will add the span around the first word
   in any title, such as post titles, page titles, and the_title is also used for
   instance in page lists) – add something like this to functions.php of your theme:
 *     ```
       add_filter('the_title', 'span_first_word');
       function span_first_word($title) {
       $words = explode(' ', $title);
       $words[0] = '<span>'.$words[0].'</span>';
       $title = implode(' ', $words);
       return $title;
       }
       ```
   
 *  Thread Starter [swellness](https://wordpress.org/support/users/swellness/)
 * (@swellness)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/adding-span-to-title/#post-2319053)
 * Oh my that worked like a charm! Thank you so much I thought I was going to have
   to stew over this for hours. I very much appreciate you time!
 *  [kdubya16](https://wordpress.org/support/users/kdubya16/)
 * (@kdubya16)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/adding-span-to-title/#post-2319119)
 * Any way on how to target all instances of ‘the’ within a the_title();?
 * Any feedback would be greatly appreciated, Thanks!
 *  [kendawes](https://wordpress.org/support/users/kendawes/)
 * (@kendawes)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/adding-span-to-title/#post-2319123)
 * Hi Sweeper,
 * That is most excellent!! I have been looking for something like this!
 * How would I restrict this to only work on Page and Post titles?
 * Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding Span to Title’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [kendawes](https://wordpress.org/support/users/kendawes/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/adding-span-to-title/#post-2319123)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
