Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Hi @NetConstructor.com: I don't understand your question: "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." If you remove the field, how can you edit it? Can you reword? It's not clear at all to me. –  MikeSchinkel Sep 21 '10 at 6:27
    
@MikeSchinkel -- I actually tried above. If you look at an existing post edit screen and look under the post title you will see a URL. If you click on the last part of the url you can edit it. What i am trying to do is remove the additional "SLUG" metabox and screen options but KEEP the one under the post title. Does that make sense? –  NetConstructor.com Sep 21 '10 at 10:27
    
@NetConstructor - That's just a guess but please validate: Maybe this is only the case while you have your plugin running? Please verfiy with a new, clean install. –  hakre Sep 21 '10 at 22:30
    
@MikeSchinkel -- I have done a fresh install of Wordpress and have noticed this is not related to the plugin. In other words, even with no plugins installed this still happens. Can you please confirm by removing the slug metabox and trying to update the slug by clicking the url under the title? –  NetConstructor.com Sep 29 '10 at 8:49

4 Answers 4

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'  );
share|improve this answer
    
Thanks but what about hiding the "screen options" value? –  NetConstructor.com Sep 22 '10 at 10:41
    
this is what this javascript will do –  sorich87 Sep 22 '10 at 11:10
    
how/where would I add this code exactly? –  NetConstructor.com Sep 29 '10 at 8:50
    

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'  );
share|improve this answer
    
GREAT ANSWER! Do you buy chance know how to trick the system into actually removing the content instead of just hiding it without using the remove metabox function? I am essentially stuck in a situation where I would rather remove it than hide it but when I use the remove function I am unable to edit the slug when editing the url under the title. I can edit it but when I press save it just reverts to what it was before... Please let me know –  NetConstructor.com Sep 30 '10 at 0:25
    
yes, you should call it in add_meta_boxes hook. Check latest example. –  tolginho 3 hours ago
up vote 1 down vote accepted

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'  );
share|improve this answer
1  
Quite old, but for future reference it seems these days you'll have to add !important for it to work. –  Cor van Noorloos Feb 13 '12 at 22:58

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' );
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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