Sådan omdøbes WordPress admin menu- og objektnavne

Jeg arbejder i øjeblikket på et projekt, hvor jeg havde brug for at ændre ordlyden flere forskellige steder i brugergrænsefladen i WordPress' admin område. Nærmere bestemt havde jeg brug for at ændre teksten i menuen "Indlæg" samt overskrifterne i indlægs-editoren og på siden til håndtering af kategorier.

Aaron Summers sørgede for opskriften til at ændre navnene i indlægsmenuen samt overskriften i indlægs-editoren. Føj følgende til dit theme's functions.php for at omdøge 'Posts' til 'Products':

[php] // Change the menu item labels function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Products'; $submenu['edit.php'][5][0] = 'Products'; $submenu['edit.php'][10][0] = 'Add Products'; $submenu['edit.php'][15][0] = 'Products Category'; // Change name for categories $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags echo ''; } add_action( 'admin_menu', 'change_post_menu_label' );

// Change the post object labels function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'Products'; $labels->singular_name = 'Product'; $labels->add_new = 'Add Products'; $labels->add_new_item = 'Add Product'; $labels->edit_item = 'Edit Product'; $labels->new_item = 'Product'; $labels->view_item = 'View Product'; $labels->search_items = 'Search Products'; $labels->not_found = 'No Products found'; $labels->not_found_in_trash = 'No Products found in Trash'; } add_action( 'init', 'change_post_object_label' ); [/php]

Sådan ændres taksonomi-overskrifterne

Endvidere gav Aaron's indlæg mig et hint om, hvor jeg kunne finde en måde at ændre default taksonomi-overskrifterne. Nemlig omkring linie 396 (WP 3.6) i wp-includes/taxonomy.php. Føj følgende til dit theme's functions.php og omdøb efter ønske:

[php] function change_tax_object_label() { global $wp_taxonomies; $labels = &$wp_taxonomies['category']->labels; $labels->name = __('Your Taxonomy Names', 'theme_namespace'); $labels->singular_name = __('Your Taxonomy Name', 'theme_namespace'); $labels->search_items = __('Search Your Taxonomy Names', 'theme_namespace'); $labels->all_items = __('All Your Taxonomy Names', 'theme_namespace'); $labels->parent_item = __('Your Parent Taxonomy Name', 'theme_namespace'); $labels->parent_item_colon = __('Your Parent Taxonomy Name:', 'theme_namespace'); $labels->edit_item = __('Edit Your Taxonomy Name', 'theme_namespace'); $labels->view_item = __('View Your Taxonomy Name', 'theme_namespace'); $labels->update_item = __('Update Your Taxonomy Name', 'theme_namespace'); $labels->add_new_item = __('Add Your Taxonomy Name', 'theme_namespace'); $labels->new_item_name = __('Your New Taxonomy Name', 'theme_namespace'); } add_action( 'init', 'change_tax_object_label' ); [/php]

Bemærk venligst at jeg har lavet kodestumpen oversættelig, så husk at udskifte 'theme_namespace' med dit ... tja, theme's namespace.

Koden herover virker med kategorier, men man kan også få det til at virke med tags. Se venligst den tidligere nævnte wp-includes/taxonomy.php for at finde alle de tilgængelige tekststrenge, der kan ændres.