1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
您的第二次嘗試已經(jīng)接近尾聲,但您發(fā)現(xiàn)這對(duì)每個(gè)標(biāo)題都有效。
您需要做的是先檢查帖子類型是否為 a post,如果是則只添加 id。
add_filter('the_title', 'add_id_to_title', 10, 2);
function add_id_to_title($title, $post_id) {
? ? //use the id to check the post type and only add the id if it has a type of "post"
? ? if(get_post_type($post_id) == "post")
? ? ? ? $title = $post_id.': '.$title;
? ? return $title;
}
這是做什么的:
過濾
the_title
器可以采用 2 個(gè)參數(shù):標(biāo)題(您正在使用的)以及帖子的 ID。使用 id,可以使用內(nèi)置
get_post_type
函數(shù)找出帖子類型。然后我們可以檢查帖子類型是否是
post
,如果是我們將 id 添加到標(biāo)題。
- 1 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報(bào)