• I’m a newcomer to web development and WordPress, and the below block of code, which is supposed to change the title based on the current page, causes this error message to appear: “Parse error: syntax error, unexpected ‘{‘ in C:\xampp\htdocs\wordpress\wp-content\themes\Suravara\header.php on line 8” (line 8 is the second line, after the opening php tag). Can anyone help me out wiith this surely simple error? Thanks!

    <?php
    if ( is_single() ) { single_post_title(); }
    elseif ( is_home() || is_front_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); get_page_number(); }
    elseif ( is_page() ) { single_post_title(''); }
            elseif ( is_search() ) { bloginfo('name'); print ' | Search results for ' . wp_specialchars($s); get_page_number(); }
            elseif ( is_404() ) { bloginfo('name'); print ' | Not Found'; }
            else { bloginfo('name'); wp_title('|'); get_page_number(); }
        ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you paste all the header.php not here but to pastebin, and paste the link back here, the code looks fine, so it could be an open tag before this one?

    David

    Thread Starter Ganjanator

    (@ganjanator)

    Untested Try:
    http://pastebin.com/XMa41AM9

    If I am correct with single lines we do not need the braces {}

    if ( is_single() ) { single_post_title(); }

    This just becomes:
    if ( is_single() ) single_post_title();

    If there is more than one line nested in the statement then we do need the braces.

    elseif ( is_home() || is_front_page() ) {
       bloginfo('name'); print ' | ';
       bloginfo('description'); get_page_number();
    }

    HTH

    David

    Thread Starter Ganjanator

    (@ganjanator)

    If I take the ‘{‘ and ‘}’ from line 8, the error becomes
    Parse error: syntax error, unexpected ‘{‘ in C:\xampp\htdocs\wordpress\wp-content\themes\Suravara\header.php on line 9, and I’m pretty sure the else if on line 9 needs the braces because of multiple statements

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Header Code Trouble’ is closed to new replies.