0

As I am using the JSON API, the permalinks don't make sense. My site URLs are totally different to the ones generated by the permalinks, so this is likely to confuse the client.

Is there any way I can disable permalinks on pages and on the default post type? I was able to do it on custom post types by specifying 'public' => false but how do I make this change site-wide? Even the media pages have a permalink.

1

Since WP 4.4, there is a hook you can use to edit default arguments for registered post types:

register_post_type_args (view in context on trac)

If you're wanting to remove the permalink/slug from the edit post/page screens but not remove posts from the admin menu itself, setting public => false and show_ui => true should do that.

function remove_from_public( $args, $post_type ) {

    $args['public'] = false;
    $args['show_ui'] = true;

    // some other common uses:
    //$args['show_in_rest'] = false;
    //$args['rewrite']  = false;
    //$args['rest_base'] = false;

    return $args;
}
add_filter( 'register_post_type_args', 'remove_from_public', PHP_INT_MAX, 2 );

I use PHP_INT_MAX just to kick it to the bottom of the hook to overwrite anything that may be getting called there.

  • Hi, I have a question regarding this. When I set public to false, it does indeed disable the permalink in the admin. However this also has a side effect in Advanced Custom Fields, in that it does not appear in the "post type" dropdown. Do you know if there is any other way to disable the permalinks? – GSTAR Aug 5 '17 at 23:22
  • hmmm... yeah, that would be expected. I wonder if there is a clean way to remove that filter (or add one separately) depending on admin screen. My worry is that it is too late to do so (or that it won't get set back). Something like using $pagenow or get_current_screen() to check for an ACF basename. Basically flip it true so ACF can use it, then false everywhere else. I'd have to think about it further though, something doesn't seem right about that approach. – hwl Aug 6 '17 at 15:37

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.