WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm displaying a single "featured" post at the top of the blog index page, and category pages.

I'm using this conditional to display the category name of the category page if it is a category page, or to display one category title of the featured post if it is on the blog index page:

if( is_category() ):
    $category = strip_tags( single_cat_title() );
  echo '<div class="title main fs-45">' . $category .'<span></span></div>';
    $category = get_the_category();
  echo '<div class="title main fs-45">' . $category[0]->cat_name .'<span></span></div>';

This conditional works fine for the blog index page. However, when on a category page, the html result places the category title outside of the <div class="title main fs-45"></div>.

For example, on "My Current Category" category page the html result looks like:

<div class="widget-box featured beige right">
My Current Category
<div class="title main fs-45"><span></span></div>

    <div class="the-content">

        ... some other html …



And on the blog index page, the html result is correct like this:

<div class="widget-box featured beige right">

<div class="title main fs-45">Featured Post Category Name<span></span></div>

    <div class="the-content">

        ... some other html …



Any ideas why this would be happening?

Thanks for any help with this!

share|improve this question
Some function is echoing when it should be returning but without more code I can't say much else. – s_ha_dum Dec 3 '12 at 17:42
Some WordPress functions return their output, and some echo their output. When this sort of issue comes up, it is almost always a case of a function echoing output rather than returning it as the user intends. I would highly recommend starting with the function's Codex entry, and verifying output echo vs. return. (Note: WordPress functions that return rather than echo their output almost always start with get_.) – Chip Bennett Dec 3 '12 at 18:51
up vote 2 down vote accepted

By default single_cat_title(), a wrapper for single_term_title(), outputs the category name.
Try replacing that call with single_cat_title('',false).

share|improve this answer
Thank you, that was it! Replacing single_cat_title() with single_cat_title('',false) was the fix :) – ByteMyPixel Dec 3 '12 at 23:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.