I'm trying to echo out dynamic php titles depends on page for seo purposes.
I successfully did this the pages I call from database depends on their id's.
Like that:
if (isset($_GET["category_id"])) {
$query = $handler->query("SELECT * FROM categories WHERE category_id = ".$_GET['category_id']." ");
while($r = $query->fetch()) {
$title = $r["title"];
}
}
And this is how I echo out:
<title><?php if (isset($_GET["category_id"])) { echo $title; echo " |"; } ?> mypage.com</title>
result:
on category.php?category_id=1
Page title is: "Category 1 | mypage.com"
*
But there are pages which is not static.
for example: index.php
, login.php
.
*
I want to figure out how to edit my code below to print "Login"
on login.php
between title tags.
<title>
<?php
if (isset($_GET["category_id"])) {
echo $title; echo " |";
}
?> mypage.com
</title>
EDIT
my login.php
is like that:
include("header.php");
content.
So I need to define $title
for login.php
in header.php
I need to add some codes to header.php
when user will see different title on login.php
, index.php
etc.
I'm able to do it category.php?category?id=1
already with the code above, but I need to also make it for login.php
, index.php
and so on.
echo str_replace(".php","","login.php")
– Dec 20 '15 at 12:50You can change login.php with your variable..