1

I'm use the following code to remove the permalink settings in a post. This work until the user presses on publish button. Then the permalink settings reappear.

add_action('admin_head', 'wpds_custom_admin_post_css');
function wpds_custom_admin_post_css() {

    global $post_type;

    if ($post_type == 'post_type') {
        echo "<style>#edit-slug-box {display:none;}</style>";
    }
}
2

The default post types are post, page, attachment, revision, and nav_menu_item.

Replace 'post_type' with 'post':

add_action('admin_head', 'wpds_custom_admin_post_css');
function wpds_custom_admin_post_css() {

    global $post_type;

    if ($post_type == 'post') {
        echo "<style>#edit-slug-box {display:none;}</style>";
    }
}

If you want to remove it for multiple post types (i.e. post, page, or any custom post types you might have), change line #6 above:

     if ( in_array($post_type, array( 'post', 'page', 'your_own_post_type' )) ) {

If you only want to remove it from posts for non-admins, change line #6 above:

     if ( ($post_type == 'post') && (! current_user_can( 'administrator' )) ) {

Additionally, if you want to remove the slug meta box for posts, add:

add_action( 'admin_menu', 'custom_remove_meta_boxes' );
function custom_remove_meta_boxes() {
    if ( ! current_user_can( 'administrator' ) ) {
        remove_meta_box('slugdiv', 'post', 'normal');
    }
}
  • Thanks. I now see what I've done wrong. I work with custom post. I need to change the name of the post. If I have multiple custom posts, do I need to add this add action again for each, or can I add the post IDs with a comma? – Arnolddew Aug 13 '14 at 9:01
  • I updated answer above for multiple post types, see second code snippet. You can replace 'post', 'page', 'your_own_post_type', or add additional default or custom post types, in the array to check. – Gabriel Aug 13 '14 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.