Support » Themes and Templates » Modify h1/h2 rules on my theme

  • Resolved silis25



    I would like to modify h1/h2 rules on my theme as follows:

    1. On Front page: Site Title=h1 and Article titles=h2
    2. On Single Post Pages: Site title=h2 and Article titles=h1

    I would like to know what php code to add to make this happen.


    Kfir Silis


    <?php get_header( header.php ); ?>
    <div id="content">
    <div class="inside">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <div class="post">
    <p class="date"><?php the_date(); ?></p>
    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="largepic"><center>
        $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
        if ( ! is_array($attachments) ) continue;
        $count = count($attachments);
        $first_attachment = array_shift($attachments);
        $size = 'full';
        <?php echo wp_get_attachment_image($first_attachment->ID, $size); ?>
    <div id="post-content">
    <div class="content-text">
      the_content('Read the full post',true);
      $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
      echo $postOutput;
    <div class="content-img">
      preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
      for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
        echo $beforeEachImage . $matches[1][$i] . $afterEachImage;}?>
    <div class="clear"></div>
    <ul id="share">
    <div class="fb-like" data-href="<?php the_permalink(); ?>" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-font="trebuchet ms"></div>
    <div class="clear"></div>
    <div style="margin-bottom: -90px;" class="fb-comments" data-href="<?php the_permalink(); ?>" data-num-posts="5" data-width="940"></div>
    <?php endwhile; ?>
    <?php get_footer( footer.php ); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Max


    check out the conditional tags, specifically is_home() and is_single().

    You can achieve that with those conditionals and a couple of if statements.

    I will look into it.
    Do you have any example of such a use?

    When I think about it, I would prefer all of my titles to be h1 tagged (homepage or single) so if I change that line from:

    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>


    <h1 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>

    That will do the trick but the style of the titles is much bigger and different. So I’ve added the following on style.css:

    #content h1 a {
    	color: #d33300;
    	font-weight: normal;
    #content h1 a:hover {
    	color: #000;
    .title {
    font-size: 1.5em;
    font-weight: bold;
    font-family: Georgia;

    How can I imitate exactly h2 style into class “title”?

    OK now it’s ok.
    Thank you 🙂

    Forgot to mark the topic as resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Modify h1/h2 rules on my theme’ is closed to new replies.