brooklyndesignstudio

Add Categories to Pages

Jul 1st, 2020
691
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function add_taxonomies_to_pages() {
  2.  register_taxonomy_for_object_type( 'post_tag', 'page' );
  3.  register_taxonomy_for_object_type( 'category', 'page' );
  4.  }
  5. add_action( 'init', 'add_taxonomies_to_pages' );
  6.  if ( ! is_admin() ) {
  7.  add_action( 'pre_get_posts', 'category_and_tag_archives' );
  8.  
  9.  }
  10. function category_and_tag_archives( $wp_query ) {
  11. $my_post_array = array('post','page');
  12.  
  13.  if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
  14.  $wp_query->set( 'post_type', $my_post_array );
  15.  
  16.  if ( $wp_query->get( 'tag' ) )
  17.  $wp_query->set( 'post_type', $my_post_array );
  18. }
RAW Paste Data