Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Last active March 21, 2018 09:38
Show Gist options
  • Save imvaskii/cefe52463833b117f409703478baf383 to your computer and use it in GitHub Desktop.
Save imvaskii/cefe52463833b117f409703478baf383 to your computer and use it in GitHub Desktop.
Rename posts label to "Articles"
<?php
// Alters post type labels.
add_action( 'registered_post_type', 'change_post_type_labels', 10, 2 );
// Posts menu label change to articles.
add_action( 'admin_menu', 'rename_post_menu_item_label' );
/**
* Replace Posts label to Articles in post edit admin page
*
**/
function rename_post_menu_item_label() {
global $menu;
global $submenu;
// 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes
foreach ( $menu as $key => $menu_item ) {
// Subkey can be zero as well so $sub_key > -1 is used here.
if ( in_array( 'Posts', $menu_item ) ) {
if ( isset( $menu[ $key ] ) ) {
$menu[ $key ][0] = 'Articles';
$menu[ $key ][6] = 'dashicons-media-document';
}
if ( isset( $submenu['edit.php'][ $key ] ) ) {
$submenu['edit.php'][ $key ][0] = 'All Articles';
}
break;
}
}
}
/**
* Fires after a post type is registered .
*
* @since 3.3.0
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object .
*
* @param string $post_type Post type .
* @param WP_Post_Type $post_type_object Arguments used to register the post type .
**/
public function change_post_type_labels( $post_type, $post_type_object ) {
if ( 'post' !== $post_type ) {
return;
}
$labels = $post_type_object->labels;
$labels->name = 'Articles';
$labels->singular_name = 'Article';
$labels->add_new = 'Add Article';
$labels->add_new_item = 'Add Article';
$labels->edit_item = 'Edit Article';
$labels->new_item = 'Article';
$labels->view_item = 'View Article';
$labels->search_items = 'Search Articles';
$labels->not_found = 'No Articles found';
$labels->not_found_in_trash = 'No Articles found in Trash';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment