• 0

PHP Title


Question

Greetings Guys,

I would like to know how to change the title tag depending on the current page.

For instance if the page is "index.html" the title needs to change to "WoopAds". However, if it's any other page on the website it should be displayed as "Page Title | WoopAds".

Here is the current title code found in the headerfile:

<title>{$page_info.title} | WoopAds</title>

Thanks and awaiting for your replies!

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

No, I needed to know at what level of knowledge to assume.

OK, so finding out the current URL is your first step... I tend to use "$_SERVER['SCRIPT_NAME']"

Then you could use a conditional such as "if" to see if you are on the homepage. However a SWITCH/CASE will allow you to set a variable called $pageTitle for any page...

Then simply render this out in place of your title tag.

Link to comment
Share on other sites

  • 0

Well i'll try this out. I am sure the following code below is incorrect but I am sure someone can help me out. Pseudo Code will have to do for now.

<title>

<?php
if (filename=="index.html" OR "index.php") {$page_info.title}

else {$page_info.title} | WoopAds ;
?>

</title>

OR even simpler:

<?php
if (filename=="index.html" OR "index.php") WoopAds Classified Ads

else {$page_info.title} | WoopAds ;
?>

</title>

Any ideas how to get the correct code?

Thanks in advance!

Link to comment
Share on other sites

  • 0

that's completely wrong lol

<title>

<?php
$path_parts = pathinfo($_SERVER['REQUEST_URI']);
echo $path_parts['dirname']." | WoopAds";
?>

</title>

untested, but it should work

Link to comment
Share on other sites

  • 0

Thanks for the quick answer.

How about this:



<title>

<?php
if (basename($_SERVER['REQUEST_URI'])=="index.html")

{$page_info.title}; 

else

{$page_info.title} | WoopAd

?>

</title>

Link to comment
Share on other sites

  • 0

Thanks for the quick answer.

How about this:



<title>

<?php
if (basename($_SERVER['REQUEST_URI'])=="index.html")

{$page_info.title}; 

else

{$page_info.title} | WoopAd

?>

</title>

nope.. try this

<title>

&lt;?php
$path_parts = pathinfo($_SERVER['REQUEST_URI']);
$dirname = $path_parts['dirname'];
if($dirname == "index") {
echo "something here | WoopAds";
} else {
echo "$dirname | WoopAds";
}
?&gt;

</title>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.