Modification des étiquettes du menu Admin
-
-
Peut-être devriez-vous diviser celaen deux questions différentes: * "Renommer les éléments dumenu admin" *et * "Changer l'ordre des éléments dumenu admin" *?Cela vous aidera à obtenirplus de vuespour votre question.Maybe you should split this up into two different questions: *"Renaming admin menu items"* and *"Changing the order of admin menu items"*? This will help you get more views for your question.
- 0
- 2011-02-13
- Jan Fabry
-
5 réponses
- votes
-
- 2011-02-12
Voici leprocessuspour changer les libellés (j'ai changé lesmessagesen "contacts" dansmonexemple)
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Contacts'; $submenu['edit.php'][5][0] = 'Contacts'; $submenu['edit.php'][10][0] = 'Add Contacts'; $submenu['edit.php'][15][0] = 'Status'; // Change name for categories $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'Contacts'; $labels->singular_name = 'Contact'; $labels->add_new = 'Add Contact'; $labels->add_new_item = 'Add Contact'; $labels->edit_item = 'Edit Contacts'; $labels->new_item = 'Contact'; $labels->view_item = 'View Contact'; $labels->search_items = 'Search Contacts'; $labels->not_found = 'No Contacts found'; $labels->not_found_in_trash = 'No Contacts found in Trash'; } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
Pourmodifier l'ordre desmenus,procédez comme suit:
// CUSTOMIZE ADMIN MENU ORDER function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // this represents the dashboard link 'edit.php', //the posts tab 'upload.php', // the media manager 'edit.php?post_type=page', //the posts tab ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order');
J'ai du codepour supprimer des éléments,maisilestglobalet nonbasé sur leniveau d'accès de l'utilisateur
Here's the process to change the labels (I changed posts to "contacts" in my example)
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Contacts'; $submenu['edit.php'][5][0] = 'Contacts'; $submenu['edit.php'][10][0] = 'Add Contacts'; $submenu['edit.php'][15][0] = 'Status'; // Change name for categories $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'Contacts'; $labels->singular_name = 'Contact'; $labels->add_new = 'Add Contact'; $labels->add_new_item = 'Add Contact'; $labels->edit_item = 'Edit Contacts'; $labels->new_item = 'Contact'; $labels->view_item = 'View Contact'; $labels->search_items = 'Search Contacts'; $labels->not_found = 'No Contacts found'; $labels->not_found_in_trash = 'No Contacts found in Trash'; } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
To change the menu order, go with this:
// CUSTOMIZE ADMIN MENU ORDER function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // this represents the dashboard link 'edit.php', //the posts tab 'upload.php', // the media manager 'edit.php?post_type=page', //the posts tab ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order');
I've got code to remove items, but it's globally and not based on user access level
-
C'estexcellentmerci!Maintenant,j'aijustebesoin detrouver unmoyen de déplacer un élément de sous-menu (ex. Menus)en tant quebouton demenuprincipal.Uneidée là-dessus?This is excellent thanks! Now I just need to find a way of moving a sub menu item (ex. Menus) as a main menu button. Any idea on that?
- 0
- 2011-02-13
- Adam
-
Jen'aipastesté,mais voyez si l'ajout de 'nav-menus.php' autableau le déplace vers le haut.Haven't tested, but see if adding 'nav-menus.php' to the array moves it up.
- 0
- 2011-02-13
- Norcross
-
Malheureusementnon.C'est la seulepartie quim'a dérangé.Je veuxjustepouvoirfaireen sorte que lesmenuset widgets soient leurspropresboutons afin que ce soitplusfacilepour les clients.Merci d'avoiressayéUnfortunately no. This has been the one part that has been bugging me. I just want to be able to have the menus and widgets be their own buttons so it is easier for clients. Thank you though for trying
- 0
- 2011-02-13
- Adam
-
@Norcross C'estgénial,maisest-ilpossible de l'adapterpour qu'ilpuisseinclure le domaine detexte à desfins detraduction?@Norcross This is great, but is it possible to adapt it so that it can include the text-domain for translation purposes?
- 0
- 2014-11-12
- Phill Healey
-
@PhillHealey cettefonctionne contient aucune donnéepour l'étiquetage,mais uniquement l'ordre lui-même.@PhillHealey this function doesn't contain any data for labeling at all, rather, just the order itself.
- 0
- 2014-11-12
- Norcross
-
@Norcross Bien sûr.Jepense quej'avaistrop detâches àjongler dansmatête quandj'ai écrit ça.;-)@Norcross Of course. I think I had too many tasks being juggled in my head when I wrote that. ;-)
- 0
- 2014-11-13
- Phill Healey
-
Petitindice.Jepense que c'estjusteet suffisantpour retourner vraipour le crochet `custom_menu_order`.- `add_filter ('custom_menu_order','__return_true');` La commande vient de `menu_order`.Small hint. I think it is right and enough to return true for the hook `custom_menu_order`. - `add_filter( 'custom_menu_order', '__return_true' );` The order comes from `menu_order`.
- 0
- 2015-03-30
- bueltge
-
La réponse de @ Ivan ci-dessousestmeilleure carelle utilise lefiltreintégré `post_type_labels _ {$post_type}`,quiestpluspropre.@Ivan's answer below is better since it uses the built in filter `post_type_labels_{$post_type}`, which is cleaner.
- 0
- 2018-02-20
- Ryan
-
- 2017-02-19
Pour renommer letype depublicationpar défaut (outout autre d'ailleurs),utilisez simplement lefiltre
post_type_labels_{$post_type}
. Pour lepost
par défaut,il s'agira depost_type_labels_post
. Dans le code ci-dessous setrouve la liste complète des étiquettes (WP 4.7.1
). Vousn'êtespas obligé detout changer.add_filter( 'post_type_labels_post', 'news_rename_labels' ); /** * Rename default post type to news * * @param object $labels * @hooked post_type_labels_post * @return object $labels */ function news_rename_labels( $labels ) { # Labels $labels->name = 'News'; $labels->singular_name = 'News'; $labels->add_new = 'Add News'; $labels->add_new_item = 'Add News'; $labels->edit_item = 'Edit News'; $labels->new_item = 'New News'; $labels->view_item = 'View News'; $labels->view_items = 'View News'; $labels->search_items = 'Search News'; $labels->not_found = 'No news found.'; $labels->not_found_in_trash = 'No news found in Trash.'; $labels->parent_item_colon = 'Parent news'; // Not for "post" $labels->archives = 'News Archives'; $labels->attributes = 'News Attributes'; $labels->insert_into_item = 'Insert into news'; $labels->uploaded_to_this_item = 'Uploaded to this news'; $labels->featured_image = 'Featured Image'; $labels->set_featured_image = 'Set featured image'; $labels->remove_featured_image = 'Remove featured image'; $labels->use_featured_image = 'Use as featured image'; $labels->filter_items_list = 'Filter news list'; $labels->items_list_navigation = 'News list navigation'; $labels->items_list = 'News list'; # Menu $labels->menu_name = 'News'; $labels->all_items = 'All News'; $labels->name_admin_bar = 'News'; return $labels; }
Si vous voulez unepriseen charge de l'internationalisation,utilisez simplement
__( $text, $textdomain )
comme:$labels->name = __( 'News', 'textdomain' );
J'aitrouvé lefiltre dans lafonction:
get_post_type_labels()
àpartir d'unfichierwp-includes/post.php
:/** * Filter the labels of a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to * the post type slug. * * @since 3.5.0 * * @see get_post_type_labels() for the full list of labels. * * @param object $labels Object with labels for the post type as member variables. */ $labels = apply_filters( "post_type_labels_{$post_type}", $labels );
To rename default post type (or any other for that matter) just use filter
post_type_labels_{$post_type}
. For defaultpost
it will bepost_type_labels_post
. In the code below is the full list of labels (WP 4.7.1
). You do not have to change everything.add_filter( 'post_type_labels_post', 'news_rename_labels' ); /** * Rename default post type to news * * @param object $labels * @hooked post_type_labels_post * @return object $labels */ function news_rename_labels( $labels ) { # Labels $labels->name = 'News'; $labels->singular_name = 'News'; $labels->add_new = 'Add News'; $labels->add_new_item = 'Add News'; $labels->edit_item = 'Edit News'; $labels->new_item = 'New News'; $labels->view_item = 'View News'; $labels->view_items = 'View News'; $labels->search_items = 'Search News'; $labels->not_found = 'No news found.'; $labels->not_found_in_trash = 'No news found in Trash.'; $labels->parent_item_colon = 'Parent news'; // Not for "post" $labels->archives = 'News Archives'; $labels->attributes = 'News Attributes'; $labels->insert_into_item = 'Insert into news'; $labels->uploaded_to_this_item = 'Uploaded to this news'; $labels->featured_image = 'Featured Image'; $labels->set_featured_image = 'Set featured image'; $labels->remove_featured_image = 'Remove featured image'; $labels->use_featured_image = 'Use as featured image'; $labels->filter_items_list = 'Filter news list'; $labels->items_list_navigation = 'News list navigation'; $labels->items_list = 'News list'; # Menu $labels->menu_name = 'News'; $labels->all_items = 'All News'; $labels->name_admin_bar = 'News'; return $labels; }
If you want internationalization support, just use
__( $text, $textdomain )
like:$labels->name = __( 'News', 'textdomain' );
I found the filter in function:
get_post_type_labels()
from a filewp-includes/post.php
:/** * Filter the labels of a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to * the post type slug. * * @since 3.5.0 * * @see get_post_type_labels() for the full list of labels. * * @param object $labels Object with labels for the post type as member variables. */ $labels = apply_filters( "post_type_labels_{$post_type}", $labels );
-
La réponse de Norcross étaitpeut-être lameilleure aumoment oùelle a été écrite,maisil s'agit d'une approchebeaucouppluspropre qui utilise unfiltrenatifpour obtenir lemême résultat.Norcross's answer may have been the best at the time it was written, but this is a far cleaner approach that uses a native filter to accomplish the same outcome.
- 2
- 2018-02-20
- Ryan
-
Ayant écrit l'original,je suis d'accord que cefiltreestbien meilleur.Having written the original, I agree this filter is much better.
- 2
- 2018-11-26
- Norcross
-
- 2011-02-12
Je suis d'accord. Lefichier
functions.php
offrebeaucoup deflexibilité.J'aieubesoin de certaines desmêmesfonctionnalités que vous avez décrites avec une combinaison defiltresfunctions.php
et ceplugin .D'après ce queje peux dire,ceplugin résoudrait vos deuxproblèmeset ilfonctionne égalementbien dans les situations d'installationmulti-sites.J'espère que cela aide.
I agree.. The
functions.php
file gives lots of flexibility. I've needed some of the same functionality that you described with a combination offunctions.php
filters and this plugin.From what I can tell..this plugin would accomplish both of your issues and it works well in Multi-Site install situations too. Hope that helps.
-
Oups ... shoot,désolé,je viens de voir lepeu dene pas vouloir utiliser deplugin.Ilexiste certainement desmoyens detraduire lesnomset lesemplacements des onglets avec uniquement Functions.php.Pourmoi,après avoiremprunté cette voie (enessayant d'être sanspluginpour cela),j'ai décidé que le codage supplémentairen'en valaittout simplementpas lapeine ... étant donné lafacilité d'utilisation de ceplugin.Désolé,j'aimanqué ce critère avant.Ooops...shoot, sorry, just saw the bit about not wanting to use a plugin. There are definitely ways to go about translating the tab names and placements with just the Functions.php. For me, after heading down this path (trying to be plugin-free for this) I decided that the extra coding just wasn't worth it...given how easy that plugin was to use. Sorry I missed that criteria before.
- 0
- 2011-02-12
- Ross
-
Pas deproblème Ross,je vais quandmême l'examiner.MerciNo problem Ross, I am going to look into it anyway. Thanks
- 0
- 2011-02-13
- Adam
-
- 2011-02-12
Vous voudrezpeut-être regarder cette question
et la classe qu'ils ymentionnent sur gist
qui contient lesfonctions que vous recherchez
rename_admin_menu_section()
pour renommer,parexemple,changer les articlesen articles
et vouspouvez supprimer lemenu des apparenceset créer unnouvel élément demenu de lapage supérieurepour
You might want to look at this question
and the class they mention there on gist
which holds functions that you ara looking for
rename_admin_menu_section()
to rename for instance change Posts to Articles
and you can remove the appearances menu and create you new top page menu item for
-
- 2016-02-04
L'exemple de Norcross ci-dessusestjuste,maisj'avaisbesoin de lapossibilité d'uneinternationalisation. Sij'avais la réputation,ce serait un commentaire sous la réponse de Norcross,maispuisque cen'estpas le cas,je vais simplementmettre le codemodifiéici. 'i18n_context'est unespace denoms arbitrairepour le contexte detraduction,celapourrait être lenom de votreplugin outhèmeparexemple.
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][10][0] = __('Add Contacts', 'i18n_context'); $submenu['edit.php'][15][0] = __('Status', 'i18n_context'); // Change name for categories $submenu['edit.php'][16][0] = __('Labels', 'i18n_context'); // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = __('Contacts', 'i18n_context'); $labels->singular_name = __('Contact', 'i18n_context'); $labels->add_new = __('Add Contact', 'i18n_context'); $labels->add_new_item = __('Add Contact', 'i18n_context'); $labels->edit_item = __('Edit Contacts', 'i18n_context'); $labels->new_item = __('Contact', 'i18n_context'); $labels->view_item = __('View Contact', 'i18n_context'); $labels->search_items = __('Search Contacts', 'i18n_context'); $labels->not_found = __('No Contacts found', 'i18n_context'); $labels->not_found_in_trash = __('No Contacts found in Trash', 'i18n_context'); } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
Norcross's example above is right on, but I needed the possibility of internationalization. If I had the reputation, this would be a comment under Norcross's answer, but since I don't, i'll just put the modified code here. 'i18n_context' is an arbitrary namespace for the translation context, this could be the name of your plugin or theme for example.
function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][5][0] = __('Contacts', 'i18n_context'); $submenu['edit.php'][10][0] = __('Add Contacts', 'i18n_context'); $submenu['edit.php'][15][0] = __('Status', 'i18n_context'); // Change name for categories $submenu['edit.php'][16][0] = __('Labels', 'i18n_context'); // Change name for tags echo ''; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = __('Contacts', 'i18n_context'); $labels->singular_name = __('Contact', 'i18n_context'); $labels->add_new = __('Add Contact', 'i18n_context'); $labels->add_new_item = __('Add Contact', 'i18n_context'); $labels->edit_item = __('Edit Contacts', 'i18n_context'); $labels->new_item = __('Contact', 'i18n_context'); $labels->view_item = __('View Contact', 'i18n_context'); $labels->search_items = __('Search Contacts', 'i18n_context'); $labels->not_found = __('No Contacts found', 'i18n_context'); $labels->not_found_in_trash = __('No Contacts found in Trash', 'i18n_context'); } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' );
-
Pourquoin'avez-vouspas suggéré demodifier l'autre réponse?Why didn't you suggest an edit to the other answer?
- 0
- 2016-02-04
- fuxia
-
Ehbien,je nepeuxpasencore commenter ...j'ai égalementpensé qu'un copier-collerpourrait être utile dans le cas où Norcross voudrait lemodifier.well i can't comment yet... also i thought a cut and paste could be useful in the case Norcross does want to edit it.
- 0
- 2016-02-05
- nimmolo
J'aipassé la dernièrejournée à utiliser lefichierfunctions.phppourpersonnaliserentièrement WordPresspourmes sites clients.Je suis étonné de voirtout ce quej'aipu accompliret à quelpoint celafacilitera les chosespourmes clients.
J'ai supprimé certains éléments demenupour les utilisateurs quine sontpas connectésen tant qu'administrateur.Ce quej'espère (et d'après ce quej'ai lu,je sais que celapeut êtrefait),c'est detrouver unmoyen de renommer certains des éléments demenu (barre latéralegauche dans la zone d'administration).Parexemple,changez les articlesen articles.
Si quelqu'unpeutfournir le code dufichierfunctions.php oume diriger dans la direction,je l'apprécieraisbeaucoup!