Support » Fixing WordPress » Apostrophe in Category name

  • Resolved rwwood


    I have the following in a category.php file:

      $cat_title = single_cat_title('', false);
      $category_id = get_cat_ID($cat_title);
    if ($cat_title == "Booklets" || $cat_title == "Wolves in Sheeps Clothing" || $cat_title == "Fruit that Remains") {
        $wp_query->set('orderby', 'menu_order');
        $wp_query->set('order', 'ASC');

    The file returns what it should, however “Wolves in Sheeps Clothing” should be “Wolves in Sheep’s Clothing”. If I change the code to that and change the category name also, the category.php file then lists all categories on the site rather than just those in Wolves in Sheep’s Clothing.

    How do I deal with that apostrophe in the category title so that the right posts still get listed?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Use the slug instead of the title, WordPress would have sanitize the title to make the slug, lowercase, hyphons for spaces etc:

    category.php code

    global $cat;
    $category = get_category($cat);
    $cat_slug = $category->slug;
    $the_slugs = array('booklets', 'woolves-in-sheeps-clothing' ,'fruit-that-remains');
    if (in_array( $cat_slug, $the_slugs ) ) query_posts($query_string . "&order=ASC");
    <?php if ( have_posts() ) : ?>

    This post might also help, it has category headers, custom page title, custom post description, different content layout per category, and the ‘asc’ etc:!



    I tried using the code as you posted it and got blank pages for the categories in question. I modified it to the following and got a correct listing of post in all categories on the site except for “Wolves in Sheep’s Clothing”, which returns a listing of all categories on the site. Apparently the ‘ in the title is causing problems, even though it shouldn’t.

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Go to the categories, and edit the Wolves category, and look at the field textbox for {slug} copy that value to the code!

    Testing here created the slug ‘wolves-in-sheeps-clothing’ check your slug field.



    The slug in the category is the same as what I have in the code, that is, the same as what your test yielded. Copy and pasted anyway, and there’s no chnage.

    Any new ideas on this problem? It definitely has to do with the apostrophe in the category title, and I haven’t found anything on the WP site indicating how to fix it.

    I should also mention that on the “Wolves in Sheep’s Clothing” category page, the apostrophe in the title shows up in the page source as and in the place where “Wolves in Sheep’s Clothing” is repeated as one of the categories on the site, the apostrophe in the source is '

    So, all in all, very strange.

    I just realized that the forum parsed the code, even though it was inside code tags. The two things are & # 8217; and & # 039;, but without the spaces.

    Finally I figured out how to fix this, albeit in a way that I don’t think should be necessary.

    I changed the category name to “Wolves in Sheep& # 039;s Clothing” but without the spaces in the code for the apostrophe. It now displays as it should (Wolves in Sheep’s Clothing) and also displays a list of the posts within just that category. I used Digital Raindrops suggestion to use the slug rather than the category name in the category.php file, too.


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Apostrophe in Category name’ is closed to new replies.