Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In heading.php of the Leaf Theme there is the following code:


    <?php $header_image = get_header_image();
    if ( ! empty( $header_image ) ) { ?>
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
            <img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
       </a>
    <?php } else { ?>
         <hgroup>
              <h1 class="site-title"><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
              <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
         </hgroup>

   <?php } ?>

I want to add a text to the header image and wrap that text into H1 tags for the homepage and h6 for all other pages. The Else part doesn't have too much importance as I will only be using a image. I included it because it´s part of the code.

I have tried for a while now but I simply don´t know enough of PHP to pull it off.

share|improve this question
1  
I don't know what you mean by "add text to the header image" –  s_ha_dum Feb 24 '13 at 0:47

1 Answer 1

try is_front_page() conditional function

<?php } else { ?>
         <hgroup>
              <?php $is_front_page = is_front_page() ? 'h1' : 'h6'; ?>
              <<?php echo $is_front_page ?> class="site-title"><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
              <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
         </hgroup>

   <?php } ?>

Edit

To address the OP's question about adding to the header image:

<?php $header_image = get_header_image();
if ( ! empty( $header_image ) ) { ?>
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
        <img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
   </a>
   <?php 
   /* Start new code here */
   $heading = ( is_front_page() ? 'h1' : 'h6' );
   ?>
   <<?php echo $heading; ?>>INSERT TEXT HERE</<?php echo $heading; ?>>
   <?php 
   /* End new code here */ 
   ?>
<?php } else { ?>
share|improve this answer
    
The OP wanted to add new text to the first part of the header_image conditional. Since your is_front_page() approach is correct, I just added to your answer, rather than creating a second answer. –  Chip Bennett Feb 24 '13 at 3:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.