user2572475
user2572475

Reputation:

Displaying header dependent on page in php

I have no idea why this is not working

<?php $title = the_title(); ?>

<h1 class="top-entry-title">

  <?php if( $title === "News" ): ?>

     <?php the_title(); ?>

   <?php endif; ?></h1>

it just shows the title for every page even if it isn't equal to news ?

Upvotes: 0

Views: 73

Answers (3)

Sunil Kumar
Sunil Kumar

Reputation: 1381

You can use this:

<?php the_title( '<h1>', '</h1>' ); ?>

This would print the title to the screen as an h1.

Read here wordpress doc Codex

Upvotes: 0

TheWolf
TheWolf

Reputation: 1385

There's no echo in your code (and it's way too complicated, I think):

<?php
    if( $title === "News" )
        echo "News";
?>

should do the job.

Upvotes: 0

Bart Friederichs
Bart Friederichs

Reputation: 33521

The problem is in the top.

$title = the_title();

will print the title. See also the Wordpress Codex.

Upvotes: 1

Related Questions