繁体   English   中英

如何在内容描述中添加帖子标题?

[英]How to Add post title to content description?

使用此代码

    <?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 ...">

我想知道是否可以在代码中添加一些内容,以便在内容的开头“每年的岁月都不知道为什么……”部分之前添加单个帖子标题。

也许是这样吗?

<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     ...">

-

上面的代码在内容之前还留有很多空间,并显示出来,就像有没有办法摆脱它吗?

您可以执行以下操作:

<meta name="description" content="<?php echo get_the_title(); ?>  Everything year life dont know why but ...">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM