Are you looking for a way to hide post view and post preview admin buttons? While there’s probably a plugin for this, we have created a quick code snippet that you can use to hide post view and post preview admin buttons in WordPress.
If you want to remove “preview & view” options from the new post and post edit admin screens, then use this snippet. Don’t forget to update the post type array. Enter any post type you would like to remove the “preview and view” buttons from custom post types, posts, and pages.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function posttype_admin_css() { global $post_type; $post_types = array( /* set post types */ 'post_type_name', 'post', 'page', ); if(in_array($post_type, $post_types)) echo '<style type="text/css">#post-preview, #view-post-btn{display: none;}</style>'; } add_action( 'admin_head-post-new.php', 'posttype_admin_css' ); add_action( 'admin_head-post.php', 'posttype_admin_css' );
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 25 best tools for freelancers to scale a real business and how to set up Shopify with WordPress.
Thanks!
Do you know how I might be able to get rid of the “Post updated View post” message when I publish/update a custom post type that I’ve created? My plugin has an internal use for the CPT and it is not indented to ever be displayed, so when users click that they get a 404 page. I’d love to get rid of the link all together.
Thanks again,
Nick