Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.