Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

hdetail
hdetail
17,750 Points

Wordpress Title Tag

I'm using a static front-page for my wordpress site and the site title keeps displaying a "-" before my site name.

Any idea what's wrong?

   <?php
  if (function_exists('is_tag') && is_tag()) {
     single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
  elseif (is_archive()) {
     wp_title(''); echo ' Archive - '; }
  elseif (is_search()) {
     echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; }
  elseif (!(is_404()) && (is_single()) || (is_page())) {
     wp_title(''); echo ' - '; }
  elseif (is_404()) {
     echo 'Not Found - '; }
if (is_front_page()) {
     bloginfo('name'); echo ' - '; bloginfo('description'); }
  else {
      bloginfo('name'); }
  if ($paged>1) {
     echo ' - page '. $paged; }
?>

6 Answers

hdetail
hdetail
17,750 Points

Sorry about the formatting...

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi Spyros,

One thing I noticed is that it looks like there is an extra parenthesis here in your first if statement

single_tag_title("Tag Archive for ""); echo '" - ';

Should be

single_tag_title("Tag Archive for "); echo '" - ';

Try fixing that and see if it changes anything, if not, I'll take another look :)

hdetail
hdetail
17,750 Points

Nah no difference :/

hdetail
hdetail
17,750 Points

I just went back to using the default Twenty Eleven title. Chickened my way out of it :(

You can modify title tags for your blog from wordpress admin area - settings -> general I always use an SEO plugin (Yoast WordPress SEO is great and free) to generate an SEO title tag.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

I would definitely recommend an SEO plugin for this as well. It will take some of the complexity out of your template code and allow for more flexibility and customization of the title tags.