[WordPress] トップ・固定・投稿などページ種別に応じた条件分岐タグまとめ
![[WordPress] トップ・固定・投稿などページ種別に応じた条件分岐タグまとめ](https://markleaps.com/blog/wp-content/uploads/2025/05/wp-conditional-tags.jpg)
WordPressでは、ページの種類(トップページ、固定ページ、投稿ページなど)によって表示を切り替えたい場面がよくあります。
そのような時に便利なのが「条件分岐タグ」です。
この記事では、使用頻度の高いページ種別ごとの条件分岐タグをまとめました。
トップページに関する条件分岐
|
1 2 3 4 5 |
<?php if ( is_home() || is_front_page() ) : ?> トップページにのみ表示する内容 <?php else: ?> それ以外のページで表示する内容 <?php endif; ?> |
固定ページに関する条件分岐
固定ページ全体(is_page)
|
1 2 3 |
<?php if ( is_page() ) : ?> 固定ページにのみ表示する内容 <?php endif; ?> |
特定の固定ページ(ID)
|
1 2 3 |
<?php if ( is_page(2) ) : ?> IDが2の固定ページに表示する内容 <?php endif; ?> |
特定の固定ページ(スラッグ)
|
1 2 3 |
<?php if ( is_page( 'contact' ) ) : ?> スラッグがcontactの固定ページに表示する内容 <?php endif; ?> |
特定の固定ページ(複数)
|
1 2 3 |
<?php if( is_page( array('ページID','ページID','ページID') ) ) : ?> 指定した固定ページに表示する内容 <?php endif; ?> |
シングルページに関する条件分岐
シングルページ全体(is_single)
|
1 2 3 |
<?php if ( is_single() ) : ?> シングルページにのみ表示する内容 <?php endif; ?> |
特定のシングルページ(ID)
|
1 2 3 |
<?php if( is_single('2') ) : ?> IDが2のシングルページに表示する内容 <?php endif; ?> |
特定のシングルページ(複数)
|
1 2 3 |
<?php if( is_single( array('投稿ID','投稿ID','投稿ID') ) ) : ?> 指定したシングルページに表示する内容 <?php endif; ?> |
アーカイブに関する条件分岐
アーカイブページ(is_archive)
|
1 2 3 |
<?php if ( is_archive() ) : ?> アーカイブページにのみ表示する内容 <?php endif; ?> |
カテゴリーページ全体(is_category)
|
1 2 3 |
<?php if ( is_category() ) : ?> 全てのカテゴリーページに表示する内容 <?php endif; ?> |
特定のカテゴリーページ(ID)
|
1 2 3 |
<?php if ( is_category(2) ) : ?> IDが「2」のカテゴリーページに表示する内容 <?php endif; ?> |
特定のカテゴリーページ(スラッグ)
|
1 2 3 |
<?php if ( is_category('news') ) : ?> スラッグが「news」のカテゴリーページに表示する内容 <?php endif; ?> |
タグページ全体(is_tag)
|
1 2 3 |
<?php if ( is_tag() ) : ?> 全てのタグページに表示する内容 <?php endif; ?> |
特定のタグページ(ID)
|
1 2 3 |
<?php if ( is_tag(2) ) : ?> IDが「2」のタグページに表示する内容 <?php endif; ?> |
特定のタグページ(スラッグ)
|
1 2 3 |
<?php if ( is_tag('wordpress') ) : ?> スラッグが「wordpress」のタグページに表示する内容 <?php endif; ?> |
その他のページ
検索結果ページ(is_search)
|
1 2 3 |
<?php if ( is_search() ) : ?> 投稿検索結果ページに表示する内容 <?php endif; ?> |
404ページ(is_404)
|
1 2 3 |
<?php if ( is_404() ) : ?> 404ページに表示する内容 <?php endif; ?> |
![MARKLEAPS[マークリープス]](https://markleaps.com/blog/wp-content/themes/mkl/images/00_logo.png)

![[WordPress] プラグイン「WP ALL Import」で既存記事を一括更新(CSV上書き)する方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import_update-500x254.jpg)
![[WordPress] CSVで記事を一括インポート-プラグイン「WP ALL Import」の使い方](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import-500x254.jpg)
![[WordPress] 記事への画像挿入方法](https://markleaps.com/blog/wp-content/uploads/2025/10/pic_manual_mainimg-500x254.png)
![[WordPress] カテゴリーとタグの違いと設定方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-category-tag-500x254.jpg)