ThemeShaper Forums » Thematic

[closed]

Change document title

(4 posts)
  • Started 8 years ago by AnotherAndrew
  • Latest reply from middlesister
  • This topic is resolved
  1. AnotherAndrew
    Member

    Trying to add / edit the document title for a single page. I want to add the category name to a single page. So the document title would read "post name", "category name", then "site name".

    All I get is the post name and site name. Really want the category name!

    Why won't this work?

    if ( is_single() ) {
    		$title = single_post_title('', FALSE) . single_cat_title('', FALSE) . ' | ' . $site_name ;
        }
    Posted 8 years ago #
  2. middlesister
    Member

    I looked up the function single_cat_title and it seems to only apply to category archive pages, not single pages. This was not clear in the wordpress codex. To get a post's category from outside the loop try this. It will use the name of the first category of the post.

    if ( is_single() ) {
    	global $post:
    	$post_categories = get_the_category($post->ID);
    	$category_name = $post_categories[0]->cat_name;
    
    	$title = single_post_title('', FALSE) . $category_name . ' | ' . $site_name ;
     }
    Posted 8 years ago #
  3. AnotherAndrew
    Member

    middlesister,

    The wordpress codex is very confusing or vague at times. From reading it, the function "single_cat_title('', FALSE)" seemed like it would work!

    Thanks for your help. Your code does work after fixing "global $post;" / you had a colon in there.

    Posted 8 years ago #
  4. middlesister
    Member

    Oops, well, typed a bit too fast there. :)

    And I agree, the wordpress codex really can make you confused at times. Glad it worked!
    (And don't forget to mark as resolved)

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.