0

So, I maintain a site that puts a lot of content in modals that's pulled from custom post types. The issue I'm running into if someone (like one of our team members) goes to where they think a piece of content should be they get taken to an unstyled page of the content via the content's permalink. How can I either disable the permalinks or redirect users to the right page?

  • Do you have control over the post types? If they're not supposed to be visited then the public argument should be false. – Jacob Peattie Aug 8 '18 at 15:29
1

When defining a custom post type with register_post_type() an array of arguments is passed. Set the public parameter to 'false' to prevent generation of permalinks, as well as other associated actions (search, nav, et al).

Using the example from the WP Codex:

function codex_custom_init() {
    $args = array(
      'public' => false,
      'label'  => 'Books'
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );

https://codex.wordpress.org/Function_Reference/register_post_type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.