• Resolved TinaHunter

    (@tinahunter)


    I’ve searched all over the place but I must be missing something. I’m sure the fix for this is simple, but I’m a newbie.

    When I put this code into my header, my website comes up with an error saying “Parse error: syntax error, unexpected ‘{‘ in /home/XXXX/public_html/wp-content/themes/Wilderness/header.php on line 16”. Line 16 is the second line in the code below.

    What am I doing wrong?

    <?php
    if (is_page('about') || (is_page('credits') || (is_page('links')) {
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/widesidebar.css" type="text/css" media="screen" />
    } elseif (is_page('contact') || (is_page('media-room') || (is-page('store') || (is-page('projects')) {
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/nosidebar.css" type="text/css" media="screen" />
    } else {
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>
Viewing 11 replies - 1 through 11 (of 11 total)
  • Yes you’re not switching in and out of PHP correctly, try this…

    <?php if (is_page('about') || (is_page('credits') || (is_page('links')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/widesidebar.css" type="text/css" media="screen" />
    <?php } elseif (is_page('contact') || (is_page('media-room') || (is-page('store') || (is-page('projects')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/nosidebar.css" type="text/css" media="screen" />
    <?php } else { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    Thread Starter TinaHunter

    (@tinahunter)

    Hi t310s_

    I put in your code (straight copy and paste) and the same error message came back.

    Is it possible that my host has an issue with {‘s?

    Thread Starter TinaHunter

    (@tinahunter)

    I found this on my Host’s FAQ page. Does this effect template pages in WordPress?

    PHP Errors: Why I get “.. unexpected T_STRING …” error?

    You may get this error because all .html files are parsed as PHP here. So, if your .html file contains “<?” or “?>” tags/text (which shows for file parser that PHP code started), you get this error. This can happen with XML files if they are not using correct content type.

    If order to fix this error you need to remove “<?” and “?>” symbols or entire tags with these symbols from your HTML page source.

    a few times, you are using a hyphen – instead of the underline _ , for instance here:
    (is-page('store')

    Thread Starter TinaHunter

    (@tinahunter)

    Thanks alchymyth for catching that, but the error shows up well before I made those mistakes.

    Must be something else going on….

    Missed the typo’s, i just focussed on the PHP tags, oops.. anyway..

    How about you just post the complete code from whichever file you’re doing this in…

    The message above shouldn’t make any difference, we’re not dealing with HTML files (.htm, .html etc….)

    PHP files will accept HTML providing the syntax is correct and tags are open and closed appropriately.

    Please put the complete code in a pastebin and post the link back here.
    http://wordpress.pastebin.com/

    Have you tried is_page(array for your multiple pages?

    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    Update, noticed some more errors in the code, try this..

    <?php if (is_page('about') || is_page('credits') || is_page('links')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/widesidebar.css" type="text/css" media="screen" />
    <?php } elseif (is_page('contact') || is_page('media-room') || is_page('store') || is-page('projects')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/nosidebar.css" type="text/css" media="screen" />
    <?php } else { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    Few too many (

    @iridiax

    Does the array option support multiple page checking?
    The codex page doesn’t specifically say it does that’s why i’m asking.

    me again; after playing with the code for a while, i realized that the opening brackets infront some of the ‘if’s are wrong:

    <?php if (is_page('about') || is_page('credits') || is_page('links')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/widesidebar.css" type="text/css" media="screen" />
    <?php } elseif (is_page('contact') || is_page('media-room') || is-page('store') || is-page('projects')) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/nosidebar.css" type="text/css" media="screen" />
    <?php } else { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    hope it works 😉

    Does the array option support multiple page checking?

    Yes, and this is what I always use for my multiple page conditions.

    is_page(array(42,’about-me’,’About Me And Joe’)

    Ah i see, the example just doesn’t make it obvious…

    So a cleanup on before…

    <?php if (is_page(array('about','credits','links'))) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/widesidebar.css" type="text/css" media="screen" />
    <?php } elseif (is_page(array('contact','media-room','store','projects'))) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/nosidebar.css" type="text/css" media="screen" />
    <?php } else { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘PHP IF statement comes back with syntax error’ is closed to new replies.