Wordpress - Hide permalink and preview button and link on custom post

I just stumbled across this question and thought I'd share my most common solution which may not work for everyone in all scenarios but I believe this is the most efficient way to achieve the desired results.

When you register a CPT that does not require a single-view output in your theme or plugin, simply define the property 'public' => false,

For example a typical CPT registration might look something like this:

<?php 

/**
 * Custom Post Type: cw-programs (programs)
 * Theme: Your Custom Theme
 * Desc: A custom WP theme
 *
 * @package custom-wp-theme
 * @since   1.0.0
 * @version 1.0.0
 */
function mycpt_content_type_name() {
  $labels = array(
    'name' => __( 'My CPT'),
    'singular_name' => __( 'My CPT' ),
    'add_new' => _x('Add New', 'My CPT'),
    'add_new_item' => __('Add New My CPT'),
    'edit_item' => __('Edit My CPT'),
    'new_item' => __('New My CPT'),
    'view_item' => __('View My CPT'),
    'search_items' => __('Search My CPT'),
    'not_found' =>  __('No My CPT found'),
    'not_found_in_trash' => __('No My CPT found in Trash'), 
    );
    $args = array(
    'labels' => $labels,
    'menu_icon' => 'dashicons-clipboard',
    'public' => false,
    'publicly_queryable' => false,
    'show_ui' => true, 
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'rewrite' => array('slug' => __( 'mycpt' )),
    'supports' => array('title', 'editor'),
    'show_in_menu' => false
    ); 

    register_post_type(__( 'cw-program' ),$args);
}

add_action( 'init', 'mycpt_content_type_name' );

In one-fell-swoop, this should remove the view, slug and preview changes links from all associated admin screens. I like This solution, because it does not require any additional functions and the logic is defined in the same place as your cpt (obviously). Hope that this helps others out there, looking for a similar solution.


You can accomplish the above using hooks. Use the code below in your active theme's functions.php file to get this work

delete permalink under wordpress post title

add_filter( 'get_sample_permalink_html', 'wpse_125800_sample_permalink' );
function wpse_125800_sample_permalink( $return ) {
    $return = '';

    return $return;
}

Customizing post link from original wordpress

add_filter( 'page_row_actions', 'wpse_125800_row_actions', 10, 2 );
add_filter( 'post_row_actions', 'wpse_125800_row_actions', 10, 2 );
function wpse_125800_row_actions( $actions, $post ) {
    unset( $actions['inline hide-if-no-js'] );
    unset( $actions['view'] );

    return $actions;
}

Customizing Publish Button From Original Wordpress

Below has room for improvement, I couldn't get the hooks to do the following, so used css way to hide it.

global $pagenow;
if ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) {
    add_action( 'admin_head', 'wpse_125800_custom_publish_box' );
    function wpse_125800_custom_publish_box() {
        if( !is_admin() )
            return;

        $style = '';
        $style .= '<style type="text/css">';
        $style .= '#edit-slug-box, #minor-publishing-actions, #visibility, .num-revisions, .curtime';
        $style .= '{display: none; }';
        $style .= '</style>';

        echo $style;
    }
}

NOTES

Additional conditional statement in my case, here i've already solved for the conditional statement

global $pagenow;
if( 'edit.php' == $pagenow && isset($_GET['page_type']) == 'my-custom-post' ){
     // here i use delete post row function that explained by Maruti Mohanty on my custom post 
}

also conditional statement for add new post and custom publish metabox settings

global $pagenow;
    if( 'page-new.php' == $pagenow && isset($_GET['page_type']) == 'my-custom-post' ){
         // here i use add new post and custom publish metabox function
    }

let me know if there have another explanation.

thanks!


We can remove the Post preview, view and permalinks field by setting publicly_queryable argument to false.

setting **publicly_queryable** argument to false