最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Completely remove custom post type permalinks ("One Page" website)

matteradmin5PV0评论

I created a one page style website that I converted to WordPress. The website include a blog, but I'm not using the usual WordPress way to display the post as I'm using a modal window appearing on click to displaying it. So basically I'm not using the Pages/Posts/Comments admin sections at all. Instead I decided to go with custom post types and create my own PHP loops. This is working pretty great for now.

But I have a problem with permalinks. Everytime I want to create a CPT, there's a permalink attributed to the "post". For example here's my CPT settings for a "carousel logo display" section (I use CPT UI plugin to create my CPTs, saying it just in case) :

    "labels" => $labels,
    "description" => "",
    "public" => false,
    "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" => false,
    "exclude_from_search" => true,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => false,
    "query_var" => false,

Which is working in a way. I mean that I don't have that mywebsite/CPT_Name/blablabla/ type of links anymore. But I still have something like mywebsite/?post_type=CPT_Name&p=43 working instead (displaying my homepage), which is scary in a way.
I don't care if anyone goes on these links, because there is 0,1% of chance it happens (as of course I'll not publish/use these links at all). But I'm scared that Search engines get these permalinks in their database.

So basically, am I doing CPT the good way ? Do permalinks like the one I talked just before risks to appear on search engines ? Do I need to redirect these permalinks to my 404 page ?

Thanks a lot !

I created a one page style website that I converted to WordPress. The website include a blog, but I'm not using the usual WordPress way to display the post as I'm using a modal window appearing on click to displaying it. So basically I'm not using the Pages/Posts/Comments admin sections at all. Instead I decided to go with custom post types and create my own PHP loops. This is working pretty great for now.

But I have a problem with permalinks. Everytime I want to create a CPT, there's a permalink attributed to the "post". For example here's my CPT settings for a "carousel logo display" section (I use CPT UI plugin to create my CPTs, saying it just in case) :

    "labels" => $labels,
    "description" => "",
    "public" => false,
    "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" => false,
    "exclude_from_search" => true,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => false,
    "query_var" => false,

Which is working in a way. I mean that I don't have that mywebsite/CPT_Name/blablabla/ type of links anymore. But I still have something like mywebsite/?post_type=CPT_Name&p=43 working instead (displaying my homepage), which is scary in a way.
I don't care if anyone goes on these links, because there is 0,1% of chance it happens (as of course I'll not publish/use these links at all). But I'm scared that Search engines get these permalinks in their database.

So basically, am I doing CPT the good way ? Do permalinks like the one I talked just before risks to appear on search engines ? Do I need to redirect these permalinks to my 404 page ?

Thanks a lot !

Share Improve this question edited Apr 14, 2019 at 14:15 Rojiraan asked Apr 12, 2019 at 12:43 RojiraanRojiraan 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I think you should be able to set publicly_queryable to false, which should prevent those ugly permalinks from being generated / working.

Post a comment

comment list (0)

  1. No comments so far