WordPress.org

Ready to get started?Download WordPress

Forums

get_header() doesn't work with custom pages (16 posts)

  1. VMaklaud
    Member
    Posted 5 months ago #

    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 :

    <?php
    /*
    Template Name: About
    */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="content" class="column-full">
    			<div id="main" class="fullwidth">
    				About
    			</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?

    Thanks!

  2. VMaklaud
    Member
    Posted 5 months ago #

    Hey guys, any advice?
    I still don't see the error, everything is done with tutorials, but the header looks terrible.

  3. Christian1012
    Member
    Posted 5 months ago #

    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'); ?>
  4. VMaklaud
    Member
    Posted 5 months ago #

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

  5. Christian1012
    Member
    Posted 5 months ago #

    Can post a link to the site in question?

  6. VMaklaud
    Member
    Posted 5 months ago #

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

  7. Senff
    Member
    Posted 5 months ago #

    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?

  8. VMaklaud
    Member
    Posted 5 months ago #

    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(); ?>>
    <head>
    	<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(); ?>
    </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') ?>" />
    					</a>
    				</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>
    		</div> <!-- header -->

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

  9. VMaklaud
    Member
    Posted 5 months ago #

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

  10. VMaklaud
    Member
    Posted 5 months ago #

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

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

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

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

    <?php
    /*
    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.

  11. Christian1012
    Member
    Posted 5 months ago #

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

  12. VMaklaud
    Member
    Posted 5 months ago #

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

  13. VMaklaud
    Member
    Posted 5 months ago #

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

    <?php
    /*
    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.

  14. Giovanni Putignano
    Member
    Posted 5 months ago #

    What means "look very strange"? Please attach an image.

  15. VMaklaud
    Member
    Posted 5 months ago #

    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.]

  16. VMaklaud
    Member
    Posted 5 months ago #

    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.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.