Skip to content

Instantly share code, notes, and snippets.

@webgurus
Forked from grappler/hide-view.php
Created July 30, 2014 12:59
Show Gist options
  • Save webgurus/fb9d649cc16d2de8b0f4 to your computer and use it in GitHub Desktop.
Save webgurus/fb9d649cc16d2de8b0f4 to your computer and use it in GitHub Desktop.
<?php
/**
* Hides the 'view' button in the post edit page
*
*/
function hv_hide_view_button() {
$current_screen = get_current_screen();
if( $current_screen->post_type === 'post-type' ) {
echo '<style>#edit-slug-box{display: none;}</style>';
}
return;
}
add_action( 'admin_head', 'hv_hide_view_button' );
/**
* Removes the 'view' link in the admin bar
*
*/
function hv_remove_view_button_admin_bar() {
global $wp_admin_bar;
if( get_post_type() === 'post-type'){
$wp_admin_bar->remove_menu('view');
}
}
add_action( 'wp_before_admin_bar_render', 'hv_remove_view_button_admin_bar' );
/**
* Removes the 'view' button in the posts list page
*
* @param $actions
*/
function hv_remove_view_row_action( $actions ) {
if( get_post_type() === 'post-type' )
unset( $actions['view'] );
return $actions;
}
// Applies to non-hierarchical CPT
add_filter( 'post_row_actions', 'hv_remove_view_row_action', 10, 1 );
// Applies to hierarchical CPT
add_filter( 'page_row_actions', 'hv_remove_view_row_action', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment