I am working on WordPress site and having a problem with custom post type functionality. I have created a post type with the name “cust_team” and permalink is set to Post Name:
Post Name : http://example.com/mytheme/sample-post/
Now when I am viewing “http://example.com/mytheme/cust_team” page it shows me a list of all the “cust_team” posts. But when I am viewing http://example.com/mytheme/post or page it redirects to 404 page. I just want to block the custom post type listing page, because its creating duplicate content issue in SEO.
Here is my register post type array::
$cpt_args['cust_team'] = array(
'labels' => array(
'name' => esc_html__('Team Member','mytheme'),
'singular_name' => esc_html__('Team Member','mytheme'),
'add_new' => esc_html__('Add Team Member','mytheme'),
'add_new_item' => esc_html__('Add Team Member','mytheme'),
'edit_item' => esc_html__('Edit Team Member','mytheme'),
'new_item' => esc_html__('New Team Member','mytheme'),
'all_items' => esc_html__( 'All Team Members','mytheme'),
'not_found' => esc_html__('No Team Member found','mytheme'),
'not_found_in_trash' => esc_html__('No Team Member found in Trash','mytheme'),
'menu_name' => esc_html__('Team Members','mytheme'),
),
'description' => 'Manage Team Content.',
'public' => true,
'publicly_queryable' => true,
'show_in_nav_menus' => true,
'supports' => array(
'title',
'thumbnail',
'editor',
'page-attributes',
'custom-fields'
),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'has_archive' => true,
'menu_icon' => 'dashicons-admin-post',
'query_var' => true,
'rewrite' => '',
'capability_type' => 'post',
'map_meta_cap' => true,
'rewrite' => array('slug' => 'cust_team'),
);
Please tell me what I am doing wrong here. I want to remove custom post type listing page like default post types “post” and “page” do.
2
Answers
Set the following to false:
You can read more about post types in WordPress documentation
Please set
'has_archive' => false
and'rewrite' => false
.has_archive
rewrite
Note:
If registering a post type inside of a plugin, call flush_rewrite_rules() in your activation and deactivation hook (see Flushing Rewrite on Activation below). If flush_rewrite_rules() is not used, then you will have to manually go to Settings > Permalinks and refresh your permalink structure before your custom post type will show the correct structure.
I hope it will help you.