• Resolved gangles

    (@gangles)


    Hello all,

    I’d like to change the title of my page (defined in header.php) from:

    <title><?php if ( is_home() ) { ?><? bloginfo('name'); ?>
    <?php } else {wp_title(''); ?>&nbsp;-&nbsp;<? bloginfo('name'); } ?></title>

    To:

    <title>
       <?php if(is_home()) { } ?>
       <?php elseif(is_404()) { ?>
         404 (Page Not Found) -
       <?php } ?>
       <?php elseif(is_search()) { ?>
         Search Results for <?php echo wp_specialchars($s, 1); ?> -
       <?php } else { ?>
       <?php wp_title(); ?> -
       <?php } ?>
       <?php bloginfo('name'); ?>
    </title>

    However, it’s giving me the following error:

    Parse error: syntax error, unexpected T_ELSEIF in /wp-content/themes/default/header.php on line 10

    I’m a bit fresh when it comes to PHP, and I can’t figure out exactly what is wrong with my code syntax. Any help would be much appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter gangles

    (@gangles)

    Fixed code (and much cleaner)!

    <?php
       if(is_home()){
         echo "";
       }
       elseif(is_404()){
         echo "404 (Page Not Found) - ";
       }
       elseif(is_search()){
         echo "Search Results for ";
         echo wp_specialchars($s, 1);
         echo " - ";
       }
       else{
        echo wp_title();
        echo " - ";
       }
       echo bloginfo('name');
       ?>

    I’m not sure if the empty echo is strictly necessary.

Viewing 1 replies (of 1 total)

The topic ‘Title in Header.php Tweaking’ is closed to new replies.