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' );
Share
Improve this question
edited Jan 5, 2019 at 8:26
Nisse Engström
1151 silver badge2 bronze badges
asked Dec 25, 2018 at 14:39
MelvinMelvin
32 bronze badges
5
- Please edit your question and add the code you used to register your post type. – Milo Commented Dec 25, 2018 at 15:32
- yes Milo is right you used register_post_type('example', $args); like this – vikrant zilpe Commented Dec 26, 2018 at 5:45
- Code? I used the plugin CPT UI. – Melvin Commented Dec 26, 2018 at 10:56
- If I understand your question correctly, you want to override /slug/? If so, you can just create a standard page title Slug and it will automatically create a post_name value of "slug" which should work fine to be at /slug/ (so long as your standard permalinks are %postname% or %category%/%postname%) – majick Commented Dec 26, 2018 at 13:01
- What I’d like to do is edit the page at /slug/ indeed, however there is not really a page I can edit anywhere. I havn’t tried creating a page with the same slug just yet – Melvin Commented Dec 26, 2018 at 14:51
1 Answer
Reset to default 1Custom 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",