ElectronSurf
ElectronSurf

Reputation: 205

remove title link in single page

this is how i call the post title:

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

i have not single.php in my theme:

<?php
    if (is_singular()) {<h2><?php the_title(); ?></h2>};
    else {<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>}
?>

but above code is not working, any idea?

Upvotes: 0

Views: 186

Answers (2)

Beittil
Beittil

Reputation: 117

A good practice in cases like these is to put all your code on a new line rather than try to pack everything in a single line. This makes it easier to see a syntax error like forgetting to use '?>' as you did after the opening bracket of the if-statement.

<?php
if (is_singular()) 
{ ?>
    <h2><?php the_title(); ?></h2>
<?php }
else 
{ ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php }
?>

Though in your case it would really be better to not interrupt the coding like that all the time and just use echo to write the line.

<?php
if (is_singular()) 
{ 
    echo '<h2>'. the_title() .'</h2>';
}
else 
{
    echo '<h2><a href="'. the_permalink() .'">'. the_title() .'</a></h2>';
}
?>

Upvotes: -1

rid
rid

Reputation: 63442

That's a syntax error. You probably want something like this instead.

<?php if (is_singular()) { ?>
    <h2><?php the_title(); ?></h2>
<?php } else { ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php } ?>

Upvotes: 5

Related Questions