0

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.

1
  • 1
    I don't know what you mean by "add text to the header image"
    – s_ha_dum
    Commented Feb 24, 2013 at 0:47

1 Answer 1

3

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 { ?>
1
  • 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. Commented Feb 24, 2013 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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