dongshi7433 2018-03-22 04: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 05: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'];
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部