WordPress.org

Support

Support » Themes and Templates » Script at top of header.php breaks website (no error)

Script at top of header.php breaks website (no error)

  • I’m using the following code to forward my user should they try to visit a single custom post page. This is how header.php starts:

    <?php
    	// forward necessary single custom posts
    	if(is_singular('production')) {
    		header('Location: ' . get_permalink(11));
    	} elseif(is_singular('credit')) {
    		header('Location: ' . get_permalink(13));
    	}
    	exit;
    ?>
    <!DOCTYPE HTML>
    
    ...rest of code goes here

    However it is just giving me a white screen of death, and if I set ‘WP_DEBUG’ to ‘true’ I don’t get any error message.

    Can anyone see an issue here? I’ve had this same problem on several other websites however on some websites it works completely fine (all on the same hosting account too!)

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

    @wpyogi

    Forum Moderator

    You cannot have any code above the doctype.

    Wow really? :O

    I’m sure I’ve used this code fine on other websites. So is there no way to perform a redirect using PHP on a WordPress site?

    Chip Bennett

    @chipbennett

    Theme Review Admin

    Try removing the exit; at the end. Basically, what this code is saying is:

    1. If this is a single “production” post-type, redirect to post 11
    2. Else, if this is a single “credit” post-type, redirect to post 13
    3. Otherwise, stop processing

    I don’t see how you’d ever get anything to parse, using this code.

    Ahh yes good point! I was under the impression that you always had to use an exit statement after changing the header location?

    I’ll try moving it to within the if statements

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Script at top of header.php breaks website (no error)’ is closed to new replies.