使用此代码
<?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不知道为什么但是...”部分之前添加单个帖子标题,所以它看起来像
也许这样吗?
<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 ...">
-
上面的代码在内容之前也留下了很多空格并显示出来 还有办法摆脱这种情况吗?
答案 0 :(得分:0)
您可以执行以下操作:
<meta name="description" content="<?php echo get_the_title(); ?> Everything year life dont know why but ...">