SWELLには記事タイトルのデザインは2つあります。
- コンテンツ上
- コンテンツ内
これらは「投稿・固定ページ」のタイトルから、タイトルの表示位置で変更できます。
しかしカスタマイズでは投稿と固定記事しか個別に設定できません。
投稿タイプやタクソノミーで変える場合はSWELLフックを使って変更しましょう。
目次
SWELLで特定の記事だけページタイトルを上部に表示する方法
やり方は簡単です、条件を加えたコードをfunctions.phpに入れましょう。
特定の記事の場合
add_filter( 'swell_is_show_ttltop', function( $is_show ) {
// 投稿IDが490の投稿のみ上部に表示する
if ( is_single( 490 ) ) {
return true;
}
return $is_show;
} );
特定の投稿タイプの場合
add_filter( 'swell_is_show_ttltop', function( $is_show ) {
// 特定の投稿タイプの場合
if ( is_singular( 'news' ) ) {
return true;
}
return $is_show;
} );
特定のカテゴリーの場合
add_filter( 'swell_is_show_ttltop', function( $is_show ) {
// 特定のカテゴリーに属する場合
if ( is_single() && has_category( 'book', get_the_ID() ) ) {
return true;
}
return $is_show;
} );
特定のタグの場合
add_filter( 'swell_is_show_ttltop', function( $is_show ) {
// 特定のタグが付いている場合
if ( is_single() && has_tag( 'special-tag', get_the_ID() ) ) {
return true;
}
return $is_show;
} );
以上です。
追記│コンテンツ内に表示する方法
逆の設定にする方法も記載しておきます。
add_filter( 'swell_is_show_ttltop', function( $is_show ) {
// news 投稿タイプだけタイトルを上部に表示しない(=コンテンツ内に表示)
if ( is_singular( 'news' ) ) {
return false;
}
return $is_show; // 他はSWELLのデフォルト設定に従う
} );