Change Post Name Labels
-
I am looking to rename the post type labels set when using
register_post_typeto a different name – from Whistle(s) to Snippet(s). This can be done it seems with the following filter:post_type_labels_whistleI gave this a go with the following code in my theme
functions.phpfile:function pxlcore_whistles_post_labels( $labels ) { $labels = array( 'name' => __( 'Snippets', 'whistles' ), 'singular_name' => __( 'Snippet', 'whistles' ), 'menu_name' => __( 'Snippets', 'whistles' ), 'name_admin_bar' => __( 'Snippet', 'whistles' ), 'add_new' => __( 'Add New', 'whistles' ), 'add_new_item' => __( 'Add New Snippet', 'whistles' ), 'edit_item' => __( 'Edit Snippet', 'whistles' ), 'new_item' => __( 'New Snippet', 'whistles' ), 'view_item' => __( 'View Snippet', 'whistles' ), 'search_items' => __( 'Search Snippets', 'whistles' ), 'not_found' => __( 'No snippets found', 'whistles' ), 'not_found_in_trash' => __( 'No snippets found in trash', 'whistles' ), 'all_items' => __( 'Snippets', 'whistles' ), ); return $labels; } add_filter( 'post_type_labels_whistle', 'pxlcore_whistles_post_labels' );All that happened was all the labels disappeared. On further investigation is seems that the
$labelspassed to the filter are an object class not an array which is what I was pushing back to the filter. I suspect this is why it fails. The object class passed is:object(stdClass)#107 (14) { ["name"]=>"Whistles" ["singular_name"]=>"Whistle" ["add_new"]=>"Add New" ["add_new_item"]=>"Add New Whistle" ["edit_item"]=>"Edit Whistle" ["new_item"]=>"New Whistle" ["view_item"]=>"View Whistle" ["search_items"]=>"Search Whistles" ["not_found"]=>"No whistles found" ["not_found_in_trash"]=>"No whistles found in trash" ["parent_item_colon"]=>NULL ["all_items"]=>"Whistles" ["menu_name"]=>"Whistles" ["name_admin_bar"]=>"Whistle" }Therefore my question if anyone can help out, is how can I manipulate that object class in my function and pass the new one with the new labels back to the filter? Many thanks in advance.
The topic ‘Change Post Name Labels’ is closed to new replies.