1

I need to make the pagetitle in the header of the homepage different from that of the interior pages. It seems like a simple php fix but it is over my head. This seemed to be the solution but implementing it gave an error code : PHP if URL equals this then perform action

This is the code I have:

<?php
/**
 * The Header for our theme.
 */
?><!DOCTYPE html>
<html>
<head>

    <link href='http://fonts.googleapis.com/css?family=GFS+Didot'
          rel='stylesheet' type='text/css'>
    <title><?php wp_title('|', true, 'right'); ?></title>
    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div>
    <header class="pagetitle">
        <h1>
            <a href="<?php echo esc_url(home_url('/')); ?>">
                <?php bloginfo('name'); ?>
            </a>
        </h1>
        <nav>
            <?php wp_nav_menu(array('theme_location' => 'primary')); ?>
        </nav>
    </header>

Can someone tell me the if/else statement that will give me one on the homepage and a different on all other pages?

Community
  • 1
  • 1

3 Answers3

1

Try this:

<title>
    <?php 
        if( is_home() ) {
            echo 'Homepage Title';
        } 
        else {
            echo 'Other Pages Title';
        }
    ?>
</title>

Reference: http://codex.wordpress.org/Function_Reference/is_home

Here's what I use on my own site to display just the site title on the homepage, but the article title on subpages:

<title>
    <?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' |'; } ?> <?php bloginfo('name'); ?>
</title>

Reference: http://codex.wordpress.org/Function_Reference/wp_title

Chris Ferdinandi
  • 1,892
  • 4
  • 26
  • 34
1
if( is_home() || is_front_page() ) {
    echo 'HOMEPAGE';
} 
else {
    echo 'INTERIOR PAGES';
}
Prince Singh
  • 5,023
  • 5
  • 28
  • 32
0

The most recent edit on the question you referred to shows the correct if/else statement:

$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'your.homepage.com/url/etc') {
  echo "Homepage header text";
}
else {
  echo "Other header text";
}

A wordpress-specific solution for checking if the user is on your home page is the function is_home() which returns a boolean if the main blog page is being displayed. More details about the is_home() function found here. There are also other "conditional tags" in wordpress that come with their own functions. A list of those can be found here.

So for example, you could also rewrite the above PHP code block with the is_home() function:

if (is_home()) {
  echo "Homepage header text";
}
else {
  echo "Other header text";
}
Community
  • 1
  • 1
ajiang
  • 1,702
  • 2
  • 12
  • 12
  • You beat me to it by 60 seconds! – Chris Ferdinandi Aug 28 '13 at 02:33
  • Thanks! So I used the $host version but I'm getting every page to say my else header text. I'm assuming I should be replacing 'SERVER_NAME' with something?'code' front page text'; } else { echo '

    other text

    '; } ?> 'code'
    – user2723659 Aug 28 '13 at 11:47