0
0

More than 1 year has passed since last update.

WordPressで固定ページにカテゴリーを付与する方法

Last updated at Posted at 2021-03-19

WordPressで固定ページにカテゴリーを付与する方法を探していたら参考サイトを見つけたのでメモ。

WordPress管理画面から「外観」→「テーマエディター」→「function.php」に以下のコードを記述

add_action('init','add_categories_for_pages'); 
function add_categories_for_pages(){ 
   register_taxonomy_for_object_type('category', 'page'); 
} 
add_action( 'pre_get_posts', 'nobita_merge_page_categories_at_category_archive' ); 
function nobita_merge_page_categories_at_category_archive( $query ) { 
    if ( $query->is_category== true && $query->is_main_query() ) { 
    $query->set('post_type', array( 'post', 'page', 'nav_menu_item')); 
    } 
} 

参考記事↓ありがとうございました

WordPressのお役立ち情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0