Q & A

How to create common categories & tags for multiple custom post types in WordPress?

In WordPress, to use default categories & tags for custom post types you’ve created you need to define it in taxonomies parameter when you are creating custom post type. You can check the following example.

 function custom_post_type() {
 
// Set UI labels for Custom Post Type
$labels = array(
'name'                => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
'menu_name'           => __( 'Movies', 'twentytwenty' ),
'parent_item_colon'   => __( 'Parent Movie', 'twentytwenty' ),
'all_items'           => __( 'All Movies', 'twentytwenty' ),
'view_item'           => __( 'View Movie', 'twentytwenty' ),
'add_new_item'        => __( 'Add New Movie', 'twentytwenty' ),
'add_new'             => __( 'Add New', 'twentytwenty' ),
'edit_item'           => __( 'Edit Movie', 'twentytwenty' ),
'update_item'         => __( 'Update Movie', 'twentytwenty' ),
'search_items'        => __( 'Search Movie', 'twentytwenty' ),
'not_found'           => __( 'Not Found', 'twentytwenty' ),
'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
);
 
// Set other options for Custom Post Type
 
$args = array(
'label'               => __( 'movies', 'twentytwenty' ),
'description'         => __( 'Movie news and reviews', 'twentytwenty' ),
'labels'              => $labels,
// Features this CPT supports in Post Editor
'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy. 
'taxonomies'          => array( 'category', 'post_tag'),
'hierarchical'        => false,
'public'              => true,
'show_ui'             => true,
'show_in_menu'        => true,
'show_in_nav_menus'   => true,
'show_in_admin_bar'   => true,
'menu_position'       => 5,
'can_export'          => true,
'has_archive'         => true,
'exclude_from_search' => false,
'publicly_queryable'  => true,
'capability_type'     => 'post',
'show_in_rest' => true,
 
);
add_action( 'init', 'custom_post_type', 0 ); 

I am creating a custom post type named movie and want to use the default category and tag for it. So that I have added category and post_tag in taxonomies parameter.

Can I able to change the WordPress theme layout with CSS?

Yes, you can change the WordPress theme layout CSS. Let’s see how!! There are two ways to do that

  1. You need to create a child theme first, After creating it you can write your own CSS inside your child theme’s style.css file to override parent theme’s CSS.
  2. If you don’t want to create a child theme then it’s ok. You can also write CSS inside an additional CSS option in customization.

Comments

    1. Post
      Author

Leave a Reply

Your email address will not be published. Required fields are marked *