Domanda

Questa è una domanda interessante.

Di recente ho notato che se si utilizza il codice

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

si sono effettivamente in grado di modificare la lumaca quando si fa clic sul Slug url sotto il titolo della pagina.

Per chiarire, quando si utilizza remove_meta_box per lo slugdiv, Metabox e le opzioni di schermo vengono rimossi tuttavia si è ancora in grado di fare clic sull'URL sotto il titolo del post di modificarla ... Tuttavia, quando si va a aggiornare / pubblicare post qualunque modifica che hai fatto non tiene.

Il mio obiettivo è quello di rimuovere la stessa METABOX dalla schermata di posta di modifica e rimuoverlo dalla pagina delle opzioni schermo, ma voglio assicurare che quando si modifica la lumaca sotto il titolo del post che questo funziona ancora.

Qualcuno può fornire una soluzione a questo problema? Grazie in anticipo.

È stato utile?

Soluzione 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'  );

Altri suggerimenti

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'  );
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top