2017-07-20 38 views
0

我在編輯創作中編輯自定義文章類型標題的標題時遇到了一些麻煩。要我用這個代碼,但我有沒有運氣上手:在創世記中編輯單個自定義文章標題

add_filter('genesis_post_title_output', 'remove_single_custom_post_titles', 15); 
function remove_single_custom_post_titles($title) { 
    $title .= 'This is what I want to add to the end'; 
    return $title; 
} 

一旦我可以得到這個被添加到文章結尾我相信我可以做任何我需要能夠去做。

+0

如果我使用the_title鉤子,它只是改變頁面上的所有標題? –

+0

您需要在您的函數中添加條件,以便它僅應用於您的單一自定義帖子類型主循環..即is_singular('yourCPT')&& is_main_query() – Mohsin

回答

0
add_filter('genesis_post_title_output', 'cpt_title_singular', 15); 
function cpt_title_singular($title) { 

    if(is_singular('your-cpt-here') && is_main_query()){ 
      $title .= 'This is what I want to add to the end'; 
    } 
      return $title; 
     } 

注意代碼未經測試,請在現場申請前檢查本地主機,以避免任何錯別字。要注意的主要事項是is_singular()is_main_query()標籤,以幫助您將標題過濾器僅限於特定的CPT和主要單個帖子的標題。