我目前在我的網站頁腳有標題標籤。 這是因爲標題是動態的,如果我把它放在頭部,那麼它是空白的,因爲標題內容直到正文才會被加載。正文標題標籤(php)
我的問題是,SEO明智嗎,標題標籤在頁腳而不是標題?
我目前在我的網站頁腳有標題標籤。 這是因爲標題是動態的,如果我把它放在頭部,那麼它是空白的,因爲標題內容直到正文才會被加載。正文標題標籤(php)
我的問題是,SEO明智嗎,標題標籤在頁腳而不是標題?
我目前在我的網站頁腳有標題標籤。
這是無效的。標題標籤must be in the <head>
section:
每個HTML文檔必須必須在
HEAD
節一TITLE
元素。
此外,它可能會給現實世界的問題。我從來沒有在頁面的頁腳中看到title
標籤,我預計它們將被搜索引擎忽略。
您應該更改PHP腳本的底層架構,以便在頁面啓動時知道標題。
參考:
"if I place it in the head then it's blank, as the title content doesn't get loaded until the body."
- 這意味着你的網站設計是錯誤
您應該使用模板和適當的頁面佈局。
事實上,你的頁面代碼應該輸出什麼,但只選通器所需的數據,然後要麼拋出錯誤或致電模板
簡明的例子:
稱爲頁links.php
:
<?
//include our settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA=dbgetarr("SELECT * FROM links");
$pagetitle = "Links to friend sites";
//etc
//and then call a template:
$tpl = "links.php";
include "template.php";
?>
現在template.php
這是您的主要網站模板,由您的頁眉和頁腳組成:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My site. <?=$pagetitle?></title>
</head>
<body>
<div id="page">
<? include $tpl ?>
</div>
</body>
</html>
和links.php
是實際的頁面模板:
<h2><?=$pagetitle?></h2>
<ul>
<? foreach($DATA as $row): ?>
<li><a href="<?=$row['link']?>" target="_blank"><?=$row['name']?></a></li>
<? endforeach ?>
<ul>
簡單,乾淨和維護。
我使用了類似於Col的方法,但是這個會將您的文件名稱(即my_contact_form.php)並將其更改爲「我的聯繫表單」作爲您的頁面標題。不完全是你需要的,但我只是想給你另一種選擇。
我有一個名爲config.php的文件,其中包含我的功能等。
<?php
// dynamic page titles
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('_',' ',$page);
$page = str_replace('.php','',$page);
$page = ucwords($page);
?>
現在我只需要調用的頁面包括我想要的標題被替換
<?php require("config.php") ?>
,並使用標題如下
<title>Your Site Name » <?php echo $page; ?></title>
任何頁面上是的,它確實很重要。 – 2011-03-13 10:26:04