How to hide permalink section in WordPress backend?

If you want to hide permalink for non-admin, add this code to your plugin or function file:

<?php
// hide permalink section for non-admin
add_action('admin_head', 'wpster_remove_permalink_section');
function wpster_remove_permalink_section() {
	if( ! current_user_can('administrator')) {
		echo "<style>#edit-slug-box {display:none;}</style>";
	}    
}
?>

If you only want to hide the permalink section for a specific post type, you’ve to use something like that:

<?php
// hide planes permalink section for non-admin
add_action('admin_head', 'wpster_remove_permalink_section');
function wpster_remove_permalink_section() {
	global $post;
	if( ! current_user_can('administrator')) {
		if ( isset( $post ) ) {
			if ($post->post_type==='planes') {
				echo "<style>#edit-slug-box {display:none;}</style>";
			}
		}
	}    
}
?>

Submit a Comment

Your email address will not be published. Required fields are marked *