Skip to content

Instantly share code, notes, and snippets.

@schutzsmith
Created August 31, 2013 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schutzsmith/6400047 to your computer and use it in GitHub Desktop.
Save schutzsmith/6400047 to your computer and use it in GitHub Desktop.
Change default Post Type labels in Wordpress
function frl_change_post_labels($post_type, $args){ /* change assigned labels */
global $wp_post_types;
if($post_type != 'post')
return;
$labels = new stdClass();
$labels->name = __('Articles', 'frl');
$labels->singular_name = __('Article', 'frl');
$labels->add_new = __('Add new', 'frl');
$labels->add_new_item = __('Add new Article', 'frl');
$labels->edit_item = __('Edit Article', 'frl');
$labels->new_item = __('New Article', 'frl');
$labels->view_item = __('View Article', 'frl');
$labels->search_items = __('Search Articles', 'frl');
$labels->not_found = __('No Articles found', 'frl');
$labels->not_found_in_trash = __('No Articles found in Trash.', 'frl');
$labels->parent_item_colon = NULL;
$labels->all_items = __('All Articles', 'frl');
$labels->menu_name = __('Articles', 'frl');
$labels->name_admin_bar = __('Article', 'frl');
$wp_post_types[$post_type]->labels = $labels;
}
add_action('registered_post_type', 'frl_change_post_labels', 2, 2);
function frl_change_post_menu_labels(){ /* change adming menu labels */
global $menu, $submenu;
$post_type_object = get_post_type_object('post');
$sub_label = $post_type_object->labels->all_items;
$top_label = $post_type_object->labels->name;
/* find proper top menu item */
$post_menu_order = 0;
foreach($menu as $order => $item){
if($item[2] == 'edit.php'){
$menu[$order][0] = $top_label;
$post_menu_order = $order;
break;
}
}
/* find proper submenu */
$submenu['edit.php'][$post_menu_order][0] = $sub_label;
}
add_action('admin_menu', 'frl_change_post_menu_labels');
function frl_change_post_updated_labels($messages){ /* change updated post labels */
global $post;
$permalink = get_permalink($post->ID);
$messages['post'] = array(
0 => '',
1 => sprintf( __('Article updated. <a href="%s">View post</a>', 'frl'), esc_url($permalink)),
2 => __('Custom field updated.', 'frl'),
3 => __('Custom field deleted.', 'frl'),
4 => __('Article updated.', 'frl'),
5 => isset($_GET['revision']) ? sprintf(__('Article restored to revision from %s', 'frl'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
6 => sprintf( __('Article published. <a href="%s">View post</a>'), esc_url($permalink)),
7 => __('Article saved.', 'frl'),
8 => sprintf( __('Article submitted. <a target="_blank" href="%s">Preview</a>', 'frl'), esc_url(add_query_arg('preview','true', $permalink))),
9 => __('Article scheduled. <a target="_blank" href="%2$s">Preview</a>', 'frl'),
10 => sprintf( __('Article draft updated. <a target="_blank" href="%s">Preview</a>', 'frl'), esc_url(add_query_arg('preview', 'true', $permalink)))
);
return $messages;
}
add_filter('post_updated_messages', 'frl_change_post_updated_labels');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment