Hide View and preview from custom post types

Is it possible to hide the ability to view or preview custom post types? I as, for custom post types like carousels and other forms that render in a particular way where viewing or previewing them out side their intended rendering purpose would not make any sense.

Related posts

3 comments

  1. You need to set argument public to false at register_post_type() function.

    Whether a post type is intended to be used publicly either via the
    admin interface or by front-end users. Default: false

    • ‘false’ – Post type is not intended to be used publicly and should generally be unavailable in wp-admin and on the front end unless
      explicitly planned for elsewhere.
    • ‘true’ – Post type is intended for public use. This includes on the front end and in wp-admin.
  2. I did this by removing the post_row_action.

    So, setup a function using that filter:

    add_filter( 'post_row_actions', 'remove_view_link_cpt' );
    function remove_view_link_cpt( $action ) {
    
        unset ($action['view']);
        return $action;
    }
    

    You will want to add a check to ensure you are on your CPT page when applying this code… otherwise it will remove the ‘view’ button from all post types. You didn’t mention this in your question.. so I can’t make my answer more specific.

Comments are closed.