Support » Fixing WordPress » get_header() doesn't work with custom pages

  • Hi All!

    I’m new to WordPress and make my own simple theme. I learn different examples and google a lot, but still don’t have the answer (stackoverflow is dead now).
    I make my own custom pages (about, contact page etc), add them in the Pages section in the wp-admin, all according to this article :

    Template Name: About
    <?php get_header(); ?>
    		<div id="content" class="column-full">
    			<div id="main" class="fullwidth">
    			</div> <!-- main -->
    		</div> <!-- content -->
    <?php get_footer(); ?>

    But my custom pages look very strange in comparison with index.php. I open the page code in a browser and see that the <header> is fully empty and all the content from the header is in the body.

    What did I do wrong?


Viewing 15 replies - 1 through 15 (of 15 total)
  • Hey guys, any advice?
    I still don’t see the error, everything is done with tutorials, but the header looks terrible.

    Compare your custom page template to page.php and see if there are any glaring differences on structural level. For example, does page.php call a specific header?

    <?php get_header('default'); ?>

    Christian1012, no differences at all.
    I call the header without the parameter – just get_header(); in both index.pho and (e.g.) contact.php.

    Can post a link to the site in question?

    I don’t have a site, yet. Just making my first theme and test in using a local server.

    I open the page code in a browser and see that the <header> is fully empty and all the content from the header is in the body.

    It’s possible there are some missing tags in the header (header.php) which cause it to end up in the content. Does it work fine on other, non-custom pages?

    If we’d see a live example it may be easier for us to help. Without that, can you post the contents of header.php somewhere?

    Senff, I have only one “standard” page – index.php, others are custom (abount, contact etc.).

    Here is my header.php code. It works fine in index.php, but wrong with custom pages.

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    	<meta charset="<?php bloginfo('charset'); ?>" />
    	<title><?php wp_title(); ?></title>
    	<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />
    	<?php wp_head(); ?>
    <body <?php body_class(); ?>>
    	<div id="wrapper">
    		<div id="header">
    			<div class="column-full">
    				<div id="logo">
    					<a href="<?php echo home_url('/'); ?>" title="<?php bloginfo('name') ?>">
    						<img src="<?php echo get_template_directory_uri() . "/images/logo.png"; ?>" alt="<?php bloginfo('name') ?>" />
    				</div> <!-- logo -->
    				<div id="navigation" class="float-right">
    					<?php if (function_exists('has_nav_menu') && has_nav_menu('primary-menu')) : ?>
    						<?php wp_nav_menu(array(
    							'sort_column' => 'menu_order',
    							'container' => 'ul',
    							'menu_id' => 'main-nav',
    							'menu_class' => 'nav float-left',
    							'theme_location' => 'primary-menu')); ?>
    					<?php else : ?>
    						<ul id="main-nav" class="nav float-left">
    							<li class=""><a href="<?php echo home_url('/'); ?>">Home</a></li>
    							<li class=""><a href="<?php echo home_url('/about/'); ?>">About</a></li>
    							<li class=""><a href="<?php echo home_url('/contact/'); ?>">Contact</a></li>
    						</ul> <!-- main-nav -->
    					<?php endif; ?>
    				</div> <!-- navigation -->
    		</div> <!-- header -->

    In index.php it looks well. In custom pages <head> contains only <title> and every content (header and body) is moved left.

    I have also tried this advice, but it doesn’t help, either.

    I think I have the solution, but I don’t understand it.

    Old version of any custom page (different php tags for the commands):

    Template Name: Contact
    <?php get_header(); ?>

    New version (get_header and template name in the same php tag):

    Template Name: Contact
    php get_header(); ?>

    Now everything looks fine. But could anyone explain this to me? I think it shouldn’t be so important if I write those to commands in one or two php tags, but that really matters.

    That’s not even valid, you have a random php in there. That works?

    Why isn’t is valid? What is random php?

    This really confuses me. Here is the code from one of the WP themes:

    Template Name: Tags
    <?php get_header(); ?>

    Right my first version – two php tags. But I don’t understand why it works in their theme but doesn’t work in mine.

    What means “look very strange”? Please attach an image.

    The image is not necessary, the content just moves left and styles are not applied. The reason – empty <head> tag. And I would like to know why.

    [Moderator Note: No bumping. If it’s that urgent, consider hiring someone instead.]

    I have some corrections. The content moves left only in IE9. In chrome, firefox and opera it’s ok. But anyway the <head> is empty in any browser. Can anyone tell me the reason? Again – it’s fixed if I put Template Name and get_header() in one <?php ?> tag, but I don’t think it’s a good solution, because it MUST work even if I use two tags.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘get_header() doesn't work with custom pages’ is closed to new replies.