• In the index file of my template, the line I want to mod is:

    <h1 id=”post-<?php the_ID(); ?>”><?php the_title(); ?></h1>

    I want to add an “if” statement so that if the_title() (the title of the page) is “Home”, then not to display it.

    I’ve tried a test line as:
    <?php $pagetitle = the_title(); if ($pagetitle != “Home” ) {the_title();} ?>

    But that didn’t work :/ It just displays the page title 2x no matter the page. I suck ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jh20001

    (@jh20001)

    Never mind ^^ I got it with:

    <h1 id=”post-<?php the_ID(); ?>”><?php $pagetitle = the_title(”,”,0); if ($pagetitle != “Home” ) {the_title();} ?></h1>

    I don’t suck after all ^_^ (well…not badly at least)

    You’re going wrong doing it that way. Still works but If is Home you’re left with empty <h1> tags.

    Do it this way:

    if(!is_front_page())
    echo '<h1 id="post-'.the_ID().'>'.the_title().'</h1>'
    Thread Starter jh20001

    (@jh20001)

    Nope, that just messes the page up.

    the code suggested by @ervald mixes strings and wordpress functions, which echo the output;

    this correction might work:

    <?php if(!is_front_page()) echo '<h1 id="post-'.get_the_ID().'">'.the_title('','',0).'</h1>'; ?>

    or using your code:

    <?php $pagetitle = the_title('','',0); if ($pagetitle != "Home" ) { ?><h1 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h1><?php } ?>

    Thread Starter jh20001

    (@jh20001)

    That works, thank you. I’ll use the modified version of mine in case I have multiple pages in the future where I’d like to hide the page title from showing there. I’m a big fan of leaving room for change ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add an "if" statement to this?’ is closed to new replies.