Title: Automatic Category Creation
Last modified: August 19, 2016

---

# Automatic Category Creation

 *  Resolved [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/)
 * Hi,
 * I have created a theme which uses certain categories to display content in particular
   areas on pages. I know that I can export the categories into a file which can
   be imported when using the theme but I would prefer that these categories were
   created automatically when the theme is activated. Can anyone suggest the best
   way to do this?
 * Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029866)
 * I see that I can use wp_insert_category, but how can I call this function automatically
   on theme activation?
 *  Thread Starter [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029868)
 * Okay, l can use the functions.php file by the looks of it.
 *  Thread Starter [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029882)
 * Right, I’ve got this in my functions.php file and I was expecting it to insert
   the category on theme activation, but it isn’t doing so. Any ideas why anyone?
 * Thanks.
 *     ```
       <?php
       	function my_activation_settings($theme)
       	{
       	    if ( 'My Theme' == $theme )
       	    {
       			$my_cat = array('cat_name' => 'My Cat', 'category_description' => '', 'category_nicename' => 'my-cat', 'category_parent' => '');
       			$my_cat_id = wp_insert_category($my_cat);
   
       	    }
       	    return;
       	}
   
       	add_action('switch_theme', 'my_activation_settings');
       ?>
       ```
   
 *  Thread Starter [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029900)
 * Anyone out there? I’m trying this now.
 * Adding this to the functions.php file
 * wp_create_category(‘My category name’);
 * causes this error when I try and browse the Themes page in admin.
 * The website encountered an error while retrieving [http://localhost:8888/mysite/wp-admin/themes.php](http://localhost:8888/mysite/wp-admin/themes.php).
   It may be down for maintenance or configured incorrectly.
 * I’ve managed to get posts creating fine in functions.php but categories just 
   don’t want to play!
 * Please help.
 *  Thread Starter [nospario](https://wordpress.org/support/users/nospario/)
 * (@nospario)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029901)
 * Found this, seems to do the job.
 *     ```
       $arg = array('description' => "my description", 'parent' => "cat_ID");
       $new_cat_id = wp_insert_term("cat name", "category", $arg);
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Automatic Category Creation’ is closed to new replies.

## Tags

 * ["theme activation"](https://wordpress.org/support/topic-tag/theme-activation/)
 * [automatic](https://wordpress.org/support/topic-tag/automatic/)
 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [category](https://wordpress.org/support/topic-tag/category/)
 * [wp_insert_category](https://wordpress.org/support/topic-tag/wp_insert_category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 1 participant
 * Last reply from: [nospario](https://wordpress.org/support/users/nospario/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/automatic-category-creation/#post-2029901)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
