【发布时间】:2014-03-20 12:01:22
【问题描述】:
使用此代码
<?php
$post = $wp_query->post;
$descrip = strip_tags($post->post_content);
$descrip_more = '';
if (strlen($descrip) > 155) {
$descrip = substr($descrip,0,155);
$descrip_more = ' ...';
}
$descrip = str_replace('"', '', $descrip);
$descrip = str_replace("'", '', $descrip);
$descripwords = preg_split('/[\n\r\t ]+/', $descrip, -1, PREG_SPLIT_NO_EMPTY);
array_pop($descripwords);
$descrip = implode(' ', $descripwords) . $descrip_more; $descrip = strip_shortcodes($descrip );
echo '<meta name="description" content="'.$descrip.'">'; ?>
在我的标题中输出类似这样的内容:
<meta name="description" content=" Everything year life dont know why but ...">
我想知道我是否可以在代码中添加一些内容,以便在“Everything year life dont know why but ...”部分之前添加单个帖子标题,在内容的开头,所以看起来像
也许会这样?
<meta name="description" content=" Uverworld - nano second (<-- the post title) Everything year life dont know why but ...">
换句话说
<meta name="description" content=" Uverworld - nano second Everything year life dont know why but ...">
--
上面的代码在内容前也留了很多空格,显示为 有没有办法摆脱它?
【问题讨论】:
-
为什么不把帖子标题放在
<title>元素中? -
它已经在那里了,但出于 SEO 的目的,我试图在标题的描述和描述中进行组合。
-
为什么你认为这会帮助 SEO?
-
这并不是说我认为它会对 seo 有帮助,描述元标记是必需的,因此搜索引擎不会在我的网站上随机获取内容并将其显示为描述,但我可以请知道如何去做这个?喜欢我个人的原因?为什么我这样做的原因很重要?
-
我已经回答了你的另一个问题。