dongshi7433 2018-03-22 12:57
浏览 29
已采纳

如何在php中手动添加描述和关键字?

This is my php code, and I want to add a manual description and keywords in here?

// define meta tags
$meta_title = $video['video_title'] . ' MyWebsite ';
$video['excerpt'] = (empty($video['excerpt'])) ? $video['video_title'] : $video['excerpt'];
$meta_description = generate_excerpt(str_replace('"', '"', $video['excerpt']), 150) .'...';

$meta_keywords = '';
if(is_array($tags_arr))
foreach($tags_arr as $id => $v)
{
    $meta_keywords .= $v['tag'] . ', ';
}
$meta_keywords = substr($meta_keywords, 0, -2);
// end
  • 写回答

1条回答 默认 最新

  • dongye3917 2018-03-22 13:12
    关注

    If you just want to concatenate your meta to existing meta like with the title, define an array of your meta and concatenate it.

    <?php
    $meta = [
        'title' => 'MyWebsite',
        'description' => 'My description',
        'keywords' => 'My keywords',
    ];
    
    // define meta tags
    $meta_title = $video['video_title'].' '.$meta['title'];
    $video['excerpt'] = (empty($video['excerpt'])) ? $video['video_title'] : $video['excerpt'];
    $meta_description = generate_excerpt(str_replace('"', '&quot;', $video['excerpt'].' '.$meta['description']), 150).'...';
    
    $meta_keywords = '';
    if (is_array($tags_arr)) {
        foreach ($tags_arr as $id => $v) {
            $meta_keywords .= $v['tag'] . ', ';
        }
        $meta_keywords = substr($meta_keywords, 0, -2).' '.$meta['keywords'];
    }
    

    If you want to replace the meta, then just replace the vars.

    <?php
    $meta = [
        'title' => 'MyWebsite',
        'description' => 'My description',
        'keywords' => 'My keywords',
    ];
    
    // define meta tags
    $meta_title = $video['video_title'].' '.$meta['title'];
    $meta_description = $meta['description'];
    $meta_keywords = $meta['keywords'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计