I registered a new post type, and I was wondering what the difference was between the $args and labels array. Read more about it in the codex (can't have more than two links, sorry).

For example, labels (code from this CPT tutorial)

'labels' => array(
    'name' => __( 'Super Dupers' ),
    'singular_name' => __( 'Super Duper' ),
    'add_new' => __( 'Add New' ),
    'add_new_item' => __( 'Add New Super Duper' ),
    'edit' => __( 'Edit' ),
    'edit_item' => __( 'Edit Super Duper' ),
    'new_item' => __( 'New Super Duper' ),
    'view' => __( 'View Super Duper' ),
    'view_item' => __( 'View Super Duper' ),
    'search_items' => __( 'Search Super Dupers' ),
    'not_found' => __( 'No super dupers found' ),
    'not_found_in_trash' => __( 'No super dupers found in Trash' ),
    'parent' => __( 'Parent Super Duper' ),

VS $args (code from this portfolio tutorial)

$args = array(  
        'label' => __('Portfolio'),  
        'singular_label' => __('Project'),  
        'public' => true,  
        'show_ui' => true,  
        'capability_type' => 'post',  
        'hierarchical' => false,  
        'rewrite' => true,  
        'supports' => array('title', 'editor', 'thumbnail')  

What are the advantages of each? I noticed that if I tried to use some of the labels in the $args array, nothing happened or didn't happen as expected. For example, 'add_new_item' => __( 'Add New Super Duper' ), doesn't work if I include it in the $args array. I would like for those labels to work as well as all existing code in the $args array (i don't want anything to break).


1 Answer 1


The code you posted is an incomplete copy/paste of the code from the tutorial you linked. labels is a parameter within the $args array:

$labels_array = array(
    'name' => _x('Books', 'post type general name')

$args = array(
    'labels' => $labels_array

register_post_type( 'book', $args );

$args is an array that contains an array of label parameters.

  • 1
    That's right. You should always double-check the official documentation, too.
    – Anh Tran
    Aug 21, 2012 at 6:36
  • Hmm...the tutorial I linked doesn't have 'args' in any of the code at all. I'll try the code you posted and see if I get a result.
    – Dave
    Aug 21, 2012 at 23:13
  • Look at the "Elaborate" example at the bottom. codex.wordpress.org/Function_Reference/register_post_type
    – Dave
    Aug 21, 2012 at 23:44
  • 1
    Correct, there is no 'args' parameter, note in my example that $args is the variable name I've given to the function's arguments. "args" or "arguments" is a generic term for data passed to any function, that variable could be named $portfolio_data or whatever is meaningful to you, the important part is the contents of that array. Have a read through the PHP documentation on variables, data types, and functions to understand this further.
    – Milo
    Aug 22, 2012 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.