Php 如何在内容描述中添加文章标题?
使用此代码Php 如何在内容描述中添加文章标题?,php,wordpress,Php,Wordpress,使用此代码 <?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);
<?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 ...">
为什么不把帖子标题放在
元素中呢?它已经存在了,但出于搜索引擎优化的目的,我正在尝试在标题描述和描述中进行组合。你为什么认为这会有助于搜索引擎优化?我不认为它会有助于搜索引擎优化,描述元标记是必需的,这样搜索引擎就不会在我的网站上随机出现一些东西,并将其显示为描述,但我可以知道如何做到这一点吗?因为我个人的原因?为什么我这样做的原因很重要?我已经回答了你的另一个问题。