[英]How to add content after my post title on Wordpress ? Only on the post title
[英]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.