开源cms seo meta属性合并管理

13 / Jan / 2022 PM Note 11

开源cms seo meta属性合并管理方法:1.新建一个seo.php,最近看了一下wordpress css js文件钩子调用,感觉很不错,不过开源cms大部分没有文件钩子,话不多说直接贴代码

开源cms seo meta属性合并管理

代码:

<?php if (substr_count($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],'/') == 1) { ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{z(站点标题)}}</title>
    <meta name="keywords" content="{{z(关键词)}}" /> 
    <meta name="description" content="{{z(描述)}}"/>
    <meta name="robots" content="index, follow"/>
    <link rel="canonical" href="<?php echo lianjie()?>" />
    <meta property="og:locale" content="zh_CN" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="{{z(站点标题)}}" />
    <meta property="og:description" content="{{z(描述)}}" />
    <meta property="og:url" content="<?php echo lianjie()?>" />
    <meta property="og:site_name" content="{{z(站点标题)}}" />
<?php } ?>
<?php if (substr_count($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],'/') == 2  and strpos($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '.html') == false) { ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{s(栏目标题)}} - {{z(站点标题)}}</title>
    <meta name="keywords" content="{{z(关键词)}}" /> 
    <meta name="description" content="{{z(描述)}}"/>
    <meta name="robots" content="index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large"/>
    <link rel="canonical" href="<?php echo lianjie()?>" />
    <meta property="og:locale" content="zh_CN" />
    <meta property="og:type" content="article" />
    <meta property="og:title" content="{{s(栏目标题)}} - {{z(站点标题)}}" />
    <meta property="og:url" content="<?php echo lianjie()?>" />
    <meta property="og:site_name" content="{{z(站点标题)}}" />
<?php } ?>
<?php if (strpos($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '.html') == true) { ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{$article['title']}} - {{z(站点标题)}}</title>
    <meta name="keywords" content="{{$article['keywords']}}" />
    <meta name="description" content="{{$article['keywords']}}{{$article['content']|text(200)}}..."/>
    <meta name="robots" content="index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large"/>
    <link rel="canonical" href="<?php echo lianjie()?>" />
    <meta property="og:locale" content="zh_CN" />
    <meta property="og:type" content="article" />
    <meta property="og:title" content="{{$article['title']}} - {{z(站点标题)}}" />
    <meta property="og:description" content="{{$article['keywords']}}{{$article['content']|text(200)}}..." />
    <meta property="og:url" content="<?php echo lianjie()?>" />
    <meta property="og:site_name" content="{{z(站点标题)}}" />
    <meta property="article:section" content="{{s(栏目标题,4)}}" />
    <meta property="article:published_time" content="{{$article['shijian']|date('c',this)}}" />
    <meta property="article:modified_time" content="{{$article['shijian']|date('c',this)}}" />
    <meta property="og:image" content="{{$article['pic']}}" />
    <meta property="og:image:alt" content="{{$article['title']}}" />
    <meta property="og:image:type" content="image/jpeg" />
<?php } ?>

说明:依次为主页,栏目页,文章页 可以另外自行封装参数就行调用即可!

发布评论