PHP Code for "If Homepage then XXX, else"

I am just editing the title tags for one of my sites, and I want it like (example):

For the home page: Welcome to XXXX - The Best Site for XXXX

For other pages: Welcome to XXXX

Is there a PHP query or something that I can put in the <title> tags to check if it is the homepage or not?

Thanks!

Assuming your homepage is called index.php this should work:

<title>Welcome to example.org <?php echo ($_SERVER['PHP_SELF'] == '/index.php') ? ' - The Best Site for XXXX' : ''; ?></title>

But I think he wants it different for every page.

Rather than having a ton of if/then statements, just do something like this.


<?php $title = 'Home (this changes for every page)'; ?>
<title><?php echo $title; ?> - Title Constant</title>

That’s not how I read the question. I would have given much the same answer as did Rick. :slight_smile:

Hi there

Thanks for the help, I was just after the first solution. The homepage only needs to be different, all the inner pages I can already vary.

However, it appears my site won’t parse the PHP in the title tags for some reason, I might post in the javascript section for a solution that way.

The site uses the Smarty template system if that helps!

The PHP should parse anywhere in the document, post your code.

<title>- Example.com <?php echo ($_SERVER['PHP_SELF'] == '/index.php') ? '- The #1 Source for Example ' : ''; ?>- {$pageDetail.page_name}</title>

Try it the old fashioned way


<title>- Example.com 
<?php 
if($_SERVER['PHP_SELF'] == '/index.php') {
   echo ' - The #1 Source for Example ';
} 
?>
</title>

Nope, the page wouldn’t even load that way

do you have php?

Yeah the site runs on it, I think that the templates system is stopping it from being parsed though

oh right… my bad.

I’d head over to the smarty forum and ask there - that’s probably your best bet since smarty doesn’t really use “normal” php tags and syntax.