Search code examples
wordpresscustom-post-type

What do the secondary parameters of labels and args in register_custom _post in wordpress relate too?


When registering a custom post in wordpress what does the second argument in the labels array object refer to.

What is 'textdomain'?

    <?php
$labels = array(
    'name'              => _x( 'Genres', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Genre', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Genres', 'textdomain' ),
    'all_items'         => __( 'All Genres', 'textdomain' ),
    'parent_item'       => __( 'Parent Genre', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Genre:', 'textdomain' ),
    'edit_item'         => __( 'Edit Genre', 'textdomain' ),
    'update_item'       => __( 'Update Genre', 'textdomain' ),
    'add_new_item'      => __( 'Add New Genre', 'textdomain' ),
    'new_item_name'     => __( 'New Genre Name', 'textdomain' ),
    'menu_name'         => __( 'Genre', 'textdomain' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'genre' ),
);

register_taxonomy( 'genre', array( 'book' ), $args );
    ?>

Solution

  • you'll find more explanations on Wordpress codex page about i18n : https://codex.wordpress.org/I18n_for_WordPress_Developers

    In short, textdomain is a unique identifier to prevent two same expressions in a theme and in a plugin to be always translated the exact same way.

    So if you're developing a theme, and your theme is called "My Best smart modern theme", you could use 'my-best-smart-modern-theme' as textdomain.

    If you're developing a plugin, call "Tristan's Books manager", you could use 'tristan-books-manager' as textdomain.

    Hope it's more clear and link will help you.