wp_create_category( int|string $cat_name, int $category_parent )

Add a new category to the database if it does not already exist.



(int|string) (Required) Category name.


(int) (Optional) ID of parent category.

Top ↑



Top ↑

More Information


  • $cat_name: Name for the new category.
  • $parent: Category ID of the parent category.


  • 0 on failure, category id on success.

wp_create_category() is a thin wrapper around wp_insert_category().

Because this is a wrapper, it is not suitable for entering a complex custom taxonomy element.

If the category already exists, it is not duplicated. The ID of the original existing category is returned without error.


Top ↑


File: wp-admin/includes/taxonomy.php

function wp_create_category( $cat_name, $category_parent = 0 ) {
	$id = category_exists( $cat_name, $category_parent );
	if ( $id ) {
		return $id;

	return wp_insert_category(
			'cat_name'        => $cat_name,
			'category_parent' => $category_parent,

Top ↑


Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex


    In order to create a simple category use:

     wp_create_category( 'My category name' );

    To create a category that is a child of Uncategorized (or whatever category has the ID 0), use:

    wp_create_category( 'Child of Uncategorized', 0 );

    To get id of category created and put value in variable:

    $id = wp_create_category( 'Child of Uncategorized', 0 );

You must log in before being able to contribute a note or feedback.