Javascript 根据使用js的页面,动态更改meta/title标记

Javascript 根据使用js的页面,动态更改meta/title标记,javascript,php,html,meta,Javascript,Php,Html,Meta,我有文件的结构: <? include('head.php'); include('header.php'); include('index_content.php'); include('footer.php'); include('form.php'); include('js.php'); ?> 当我创建一个新页面时,我使用这个框架并只更改页面内容。但是对于SEO优化,也有必要更改标题和元标记。是否可以根据页面使用JavaS

我有文件的结构:

<?
    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');
?>

一些头衔

您可以直接将
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');
?>

一些头衔

你能不能
你是用数据库做页面内容还是用静态页面?我在我的case@SamirKarmacharya静态页面您认为bot会等待php变量解析吗?这只是一个脚本代码,在浏览器中呈现时,它将显示易于爬网的纯文本。不需要bot来处理php。这很完美dom上的页面保存已解析的值,但bot将抓取变量“”作为内容,这是我在working@VinodLouis,这可能有用。我只是用jquery设置元内容。我说的对吗?当页面加载时,这也不起作用。它甚至不会等待你的js加载。你可以通过服务器端渲染或作为预渲染的中间件来实现这一点。
$("meta[name='description']").attr("content","<?php echo $DESCRIPTION;?>");