• Resolved christian_d

    (@christian_d)


    Hi and thanks in advance.

    So I am trying to set up my site so that each page has a different header image; I used this method:
    https://www.wprecipes.com/how-to-use-multiple-custom-headers-on-a-wordpress-theme

    My version of that header file looks like this:

    <?php
    if (is_page('editing')){
    	<?php include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerediting.php'); ?>
    }
    elseif (is_page('writing')){
    	<?php include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerwriting.php'); ?>
    }
    elseif (is_page('about-me')){
    	<?php include(TEMPLATEPATH.'/wp-content/themes/sandbox/headeraboutme.php'); ?>
    }
    elseif (is_page('contact')){
    	<?php include(TEMPLATEPATH.'/wp-content/themes/sandbox/headercontact.php'); ?>
    }
    else {
    	<?php include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerdefault.php'); ?>
    }
    ?>

    I created the corresponding .php header pages that I reference in there, only when I replace the default header file with the one I created I get this error:

    Parse error: syntax error, unexpected ‘<‘ in /home7/mayerack/public_html/jenniferacker/wp-content/themes/sandbox/header.php on line 3

    Does anyone have a clue what is going on? I don’t know which “<” would be “unexpected”, and I got this set up from that website I linked to above and it seems from the comments on there that other people used it with no problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Ok, I’m not that good at php, but I’d suggest first to get rid of the multiple php tags. The first one and the last one are necessary, but not the one inbetween, since you already tell the server you are writing in php.

    Try this one :

    <?php
    if (is_page('editing')){
        include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerediting.php');
    }
    elseif (is_page('writing')){
        include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerwriting.php');
    }
    elseif (is_page('about-me')){
        include(TEMPLATEPATH.'/wp-content/themes/sandbox/headeraboutme.php');
    }
    elseif (is_page('contact')){
        include(TEMPLATEPATH.'/wp-content/themes/sandbox/headercontact.php');
    }
    else {
        include(TEMPLATEPATH.'/wp-content/themes/sandbox/headerdefault.php');
    }
    ?>

    I don’t know if it’ll solve your problem, but you could try it.

    Also, could you post one of your header files ? like headercontact.php, or any other ? Your problem might come from something in those files.

    you are using another <?php opening tag while you are already ‘within php’.
    also, TEMPLATEPATH already points to /wp-content/themes/sandbox.
    leave only one php tag with its closing tag, and try this:

    <?php
    if (is_page('editing')){
    	 include(TEMPLATEPATH.'/headerediting.php');
    }
    elseif (is_page('writing')){
    	 include(TEMPLATEPATH.'/headerwriting.php');
    }
    elseif (is_page('about-me')){
    	 include(TEMPLATEPATH.'/headeraboutme.php');
    }
    elseif (is_page('contact')){
    	 include(TEMPLATEPATH.'/headercontact.php');
    }
    else {
    	 include(TEMPLATEPATH.'/headerdefault.php');
    }
    ?>

    Thread Starter christian_d

    (@christian_d)

    That seems to be some sort of progress. When I did that I got these errors instead:

    Warning: include(/home7/mayerack/public_html/jenniferacker/wp-content/themes/sandbox/wp-content/themes/sandbox/headerdefault.php) [function.include]: failed to open stream: No such file or directory in /home7/mayerack/public_html/jenniferacker/wp-content/themes/sandbox/header.php on line 15

    Warning: include() [function.include]: Failed opening ‘/home7/mayerack/public_html/jenniferacker/wp-content/themes/sandbox/wp-content/themes/sandbox/headerdefault.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home7/mayerack/public_html/jenniferacker/wp-content/themes/sandbox/header.php on line 15

    And then the rest of the site displays but with out its CSS styling/images.

    Thread Starter christian_d

    (@christian_d)

    Oh, god—you guys are the best. You fixed my problem. Thank you thank you thank you thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom header error’ is closed to new replies.