Last Updated: December 26, 2018
·
4.92K
· derekshirk

Remove "Edit Permalink & View Post" buttons on Custom Post Type Edit Screens

When creating custom post types within WordPress I often find that I don't need the permalink or the view post button to be displayed when editing or adding content for a specific post type. Since the content is often being styled differently on the front end this renderes the 'view post' button useless. Therefore I like to remove it.

The following code will remove the edit permalink and view post button from your edit/add custom post type screens. In this example I have allowed for three different CPTs to be targeted but you can adjust this as needed.

<?php  
function posttype_admin_css() {
global $post_type;
if($post_type == 'cpt_name' || $post_type == 'another_cpt_name' ||        $post_type == 'yet_another_cpt_name') {
echo '<style type="text/css">#edit-slug-box,#view-post-btn,#post-    preview,.updated p a{display: none;}</style>';
}
}
add_action('admin_head', 'posttype_admin_css'); 
?>

2 Responses
Add your response

A better way would be use this two hooks

<?php
// Style action for the post new page
add_action('admin_print_styles-post-new.php', 'posttype_admin_css'); 
// Style action for the post editting page 
add_action('admin_print_styles-post.php', 'posttype_admin_css'); 

So you only run your conditional check on the needed pages instead of all admin n pages.

over 1 year ago ·

You're right, that seems much better. I am going to try it out. I will update my pro-tip if I find this successful....

over 1 year ago ·