So I've created a simple custom post type for separating content in the back-end. The Custom Post Type has a slug and generates a URL using this slug, such as www.yoursite/slug/
. Any pages made in the custom posttype will be yoursite/slug/page-name
. This is correct, but now I wish to change the content of the page on yoursite/slug/
. Everytime I visit this page it will redirect me to the homepage. Is there any way to change this?
I forgot to mention I've used the plugin CPT UI. I found this code in CPT UI, not sure if it is of any use.
function cptui_register_my_cpts_kennisbank() {
/**
* Post Type: Kennisbank.
*/
$labels = array(
"name" => __( "Kennisbank", "blankslate" ),
"singular_name" => __( "Kennisbank", "blankslate" ),
);
$args = array(
"label" => __( "Kennisbank", "blankslate" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"delete_with_user" => false,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "kennisbank", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail" ),
);
register_post_type( "kennisbank", $args );
}
add_action( 'init', 'cptui_register_my_cpts_kennisbank' );
So I've created a simple custom post type for separating content in the back-end. The Custom Post Type has a slug and generates a URL using this slug, such as www.yoursite/slug/
. Any pages made in the custom posttype will be yoursite/slug/page-name
. This is correct, but now I wish to change the content of the page on yoursite/slug/
. Everytime I visit this page it will redirect me to the homepage. Is there any way to change this?
I forgot to mention I've used the plugin CPT UI. I found this code in CPT UI, not sure if it is of any use.
function cptui_register_my_cpts_kennisbank() {
/**
* Post Type: Kennisbank.
*/
$labels = array(
"name" => __( "Kennisbank", "blankslate" ),
"singular_name" => __( "Kennisbank", "blankslate" ),
);
$args = array(
"label" => __( "Kennisbank", "blankslate" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"delete_with_user" => false,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "kennisbank", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail" ),
);
register_post_type( "kennisbank", $args );
}
add_action( 'init', 'cptui_register_my_cpts_kennisbank' );
Custom post types can have a post type archive, which displays all posts of that type. In your post type registration code, it's controlled by the has_archive
argument, which is now currently false
. Change it to true
, or give it a string value to set it to something specific other than your post type slug.
"has_archive" => "kennisbank",