Title: Function !is_front_page not working
Last modified: August 30, 2016

---

# Function !is_front_page not working

 *  [julienkos](https://wordpress.org/support/users/julienkos/)
 * (@julienkos)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/function-is_front_page-not-working/)
 * Hi!
 * I am trying to add a span to blog post titles, based upon their category on the
   website and I don’t want it to show up in the home page in the widgets section
   at the bottom. Here is my code:
 * —
 * add_filter( ‘the_title’, ‘my_modify_title’, 10, 2 );
    function my_modify_title(
   $title, $id ) { if( in_category( ‘Fitness’, $id ) ) { $title = ‘<span class=”
   fitness”></span> ‘ . $title; } else if( in_category( ‘Recipe’, $id ) ) { $title
   = ‘<span class=”recipe”></span> ‘ . $title; } else if( in_category( ‘Life etc’,
   $id ) ) { $title = ‘<span class=”life”></span> ‘ . $title; } else if( in_category(‘
   Soul’, $id ) ) { $title = ‘<span class=”soul”></span> ‘ . $title; } return $title;}
 * —
 * I tried adding:
 * !is_front_page() to the if and it isn’t working.
 * add_filter( ‘the_title’, ‘my_modify_title’, 10, 2 );
    function my_modify_title(
   $title, $id ) { if( !is_front_page() && in_category( ‘Fitness’, $id ) ) { $title
   = ‘<span class=”fitness”></span> ‘ . $title; } else if( !is_front_page() && in_category(‘
   Recipe’, $id ) ) { $title = ‘<span class=”recipe”></span> ‘ . $title; } else 
   if( !is_front_page() && in_category( ‘Life etc’, $id ) ) { $title = ‘<span class
   =”life”></span> ‘ . $title; } else if( !is_front_page() && in_category( ‘Soul’,
   $id ) ) { $title = ‘<span class=”soul”></span> ‘ . $title; } return $title; }
 * —
 * Please let me know if I’m doing something wrong here…
 * The website is currently at: [http://utopiandesigns.ca/barlinfitness/](http://utopiandesigns.ca/barlinfitness/)

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/function-is_front_page-not-working/#post-6898186)
 * The problem is widgets that output post titles run their own queries, and `is_front_page()`
   is a wrapper for a WP_Query method. Thus `is_front_page()` is telling you the
   current query (the widget’s) is not a front page query, even though the widget
   is on the front page.
 * That explains it, but doesn’t offer a solution. If you’re working on a theme,
   you could set a global flag reflecting the front page status first thing in a
   template while the main query is still valid, then use that global flag in your
   conditionals instead. Yeah, I know globals are a bad practice. There are ways
   around them of course, if globals bother you, you probably know of a few.
 * If you’re working on a plugin, the same concept can be applied, except you need
   to work entirely from available hooks, you can’t conveniently place code in your
   theme templates.

Viewing 1 replies (of 1 total)

The topic ‘Function !is_front_page not working’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [is_front_page](https://wordpress.org/support/topic-tag/is_front_page/)
 * [modify title](https://wordpress.org/support/topic-tag/modify-title/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/function-is_front_page-not-working/#post-6898186)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
