• Hi

    How can I add a custom wordpress page/post to my template’s (visible) header (ie not <head></head> section).
    Specifically I only want this custom content to be visible on my sites homepage.

    I’m aware this probably requires modifications to template files, but I’m new to WP (familiar with PHP though), so not sure what tags etc to use.

    Any help on this would be appreciated.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • idealists,

    Place something similar ( by simialr I mean add the text and CSS styles needed ) to this code on either your index.php or header.php file, in the location you would like the custom information to appear. This does not need to be within the loop.

    <?php if (is_home()) { ?>
     <div class="style-name">Hello World, This is the Home Page</div>
    <?php } else { ?>
     <div class="style-name">Do Nothing</div>
    <?php } ?>
    Thread Starter idealists

    (@idealists)

    Hi doc

    Thanks for that

    Can the “Hello World, This is the Home Page” text come from a custom page (like the About page)?

    So then if one needs to update the content they could do it from within the WP admin environment.

    idealists,

    Of course this is possible, here is a sample of something you might try. I haven’t fully tried this but it should work. Below we are showing page 7 ( assume this is the About page’s ) title.

    <?php if (is_home()) { ?>
     <?php $my_query = new WP_Query('page_id=7');
          while ($my_query->have_posts()) : $my_query->the_post();
          $do_not_duplicate = $post->ID; ?>
    
      <h2 class="style-name"><?php the_title(); ?></h2>
      <?php endwhile; ?>
     </div>
    <?php } else { ?>
     <div class="style-name">Do Nothing</div>
    <?php } ?>
    Thread Starter idealists

    (@idealists)

    Thanks, I’ll give it a try.

    Thread Starter idealists

    (@idealists)

    Works a charm, thanks much.
    I changed to <?php the_content(); ?> as I wanted the actual post content.

    idealists,

    No problem, glad we could help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom content in templates header’ is closed to new replies.