我有文件的结构:
<?
include('head.php');
include('header.php');
include('index_content.php');
include('footer.php');
include('form.php');
include('js.php');
?>
当我创建新页面时,我使用此骨架并仅更改页面内容。但对于SEO优化,还需要更改标题和元标记。是否可以根据页面使用JavaScript动态更改此值。或者最好不要洗澡并写下这样的东西:
<?
include('head.php'); //beginning of the <head> tag
?>
<title>Some title</title>
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">
<?
include('header.php'); - //end of </head> tag
include('index_content.php');
include('footer.php');
include('form.php');
include('js.php');
?>
答案 0 :(得分:0)
您可以直接将php
变量转换为meta
标记,如下所示。
<?
include('head.php'); //beginning of the <head> tag
?>
<title>Some title</title>
<meta name="description" content="<?php echo $DESCRIPTION;?>">>
<meta name="keywords" content="<?php echo $KEYWORDS;?>">>
<?
include('header.php'); - //end of </head> tag
include('index_content.php');
include('footer.php');
include('form.php');
include('js.php');
?>
<强>更新强>
如果您使用jquery,这可能会起作用
$("meta[name='description']").attr("content","<?php echo $DESCRIPTION;?>");