Question

Here is an interesting question.

I have recently noticed that if you utilize the code

remove_meta_box('slugdiv', 'post', 'normal'); 

you are actually unable to modify the slug when you click on the url slug under the page title.

To clarify, when you use remove_meta_box for the slugdiv, the metabox and the screen options get removed however you are still able to click on the url under the post title to edit it... However, when you go to update/publish the post whatever modification you made does not take.

My objective is to remove the same metabox from the post edit screen AND remove it from the screen options page BUT I want to ensure that when you edit the slug under the post title that this still works.

Can anyone provide a solution to this problem? Thanks in advance.

Was it helpful?

Solution 2

I ended up just adding the following CSS to a css file I was calling in my functions.php file for the admin area:

[for="slugdiv-hide"] { 
    display: none; 
    }

#slugdiv { 
    display: none; 
    }

This removed both the screen options and the metabox while still allowing me to edit the url under the title.

UPDATED

Based on the answer provided by FXFUTURE I modified his code by extending it and including the css values for screen options and the slug metabox while ensuring that the code only gets included on the post-new.php and post.php page.

// HIDE THE SLUG METABOX AND SLUG SCREEN OPTIONS
   function hide_slug_options() {
    global $post;
    global $pagenow;
    $hide_slugs = "<style type=\"text/css\">#slugdiv, #edit-slug-box, [for=\"slugdiv-hide\"] { display: none; }</style>\n";
    if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php') print($hide_slugs);
   }
   add_action( 'admin_head', 'hide_slug_options'  );

OTHER TIPS

The box which allows slug edition under the post title is actually tied to the slug metabox. It needs it to work. So, removing the metabox will break it.

The only solution, I think, would be to use javascript or css to hide it. Something like this will work:

function hide_slug_box() {
    global $post;
    global $pagenow;
    if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php') {
        echo "<script type='text/javascript'>
            jQuery(document).ready(function($) {
                jQuery('#edit-slug-box').hide();
            });
            </script>
        ";
    }
}
add_action( 'admin_head', 'hide_slug_box'  );

You should call remove_meta_box in the add_meta_boxes hook to get it working. It tested on 4.0.

add_action( 'add_meta_boxes', 'customize_admin_backend_cpt',0 );

function customize_admin_backend_cpt () {
    remove_meta_box( 'slugdiv', 'your_cpt_goes_here', 'normal' );
}

Rather than editing your css file you can use this in your functions.php:

function hide_all_slugs() {
global $post;
$hide_slugs = "<style type=\"text/css\"> #slugdiv, #edit-slug-box { display: none; }</style>";
print($hide_slugs);
}
add_action( 'admin_head', 'hide_all_slugs'  );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top