Themes do not have an equivalent of register_activation_hook() like plugins.
You may also run into issues during a review if you’re hoping to be hosted on the repo. I’m not sure how creating categories classifies exactly, but doing things like creating post types is explicitly disallowed.
That said, you can use wp_create_category() in your functions.php file with a check to see if the category exists with term_exists(). Code below is untested.
if(!term_exists('my_category_name','category')) {
wp_create_category('my_category_name');
}
Related Posts:
- Get all categories and posts in those categories
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Combine two taxonomies in a hierarchical tree
- Get current category details the user is currently on in category.php
- Get the number of posts in a named category, outside the loop
- Test if post has a category
- Make parent categories not selectable
- I want to order categories based upon the latest post time
- Highlight current category in wp_list_categories
- How to find all posts without category and assign the “Uncategorized”?
- How to Override default update_count_callback for category
- WordPress previous_post_link exclude posts with multiple categories
- Is it possible to put tags and category information in the post as text?
- Let visitors post comments on category page
- category_description() shows raw html after version 3.x?
- Is it possible to post with Word 2007 via XML-RPC and limit categories by user?
- how to get the categories for a single post in a hierarchical way
- Make parent category not selectable when it has child categories
- Getting categories id for all products in cart
- Can I use get_adjacent_post for specific categories?
- How to Filter categories in the permalink structure
- Accessing WordPress MySQL Database via Data Connection in Visual Studio 2010 using C#
- Is there a cleaner way to get post count for a category in category.php?
- products nested by subcategories in a current category archive
- get_the_category() always returns empty array
- Show archives by year from just one category
- Post count for category and tag
- Get current_parent_category in a loop or Cat ancestor- big problem
- I Cannot Create New Category
- Archive.php filtered by pre-determined category
- category filter doesn’t work in WPML
- How do you categorize pages?
- Order of subcategories
- I cannot add more Categories to my menu
- “Categories” for six authors [closed]
- Filtering *out* a taxonomy from the admin post list
- category image taxonomy
- Categories overview that links to page displaying posts
- Category control subcategories
- Trying to add cat_ID to array for showing an image for specific Category
- display posts from specific category on a page , in thematic child theme?
- Hidde certain category from post meta
- How to add a post without assigning to a category?
- List all posts in a category with query_post() function
- How to change amount of categories listed on dashboard?
- How to display parents category and child category separately for a specific post?
- Display random categories
- Get a count of how many times a term or a category is used in posts
- Exclude a category name using cat name
- Get custom title if category
- Link To Child Category For A Post
- Post by category+author not working!
- Custom template for sub-sub-categories
- Simple way to style posts of a single category differently in the loop and in single
- show WordPress categories with different Structure
- How to remove the tilte “category:category name”?
- why category__and and category__in wont work togather?
- wp_dropdown_categories initial value
- Advanced permalinks structure
- Subcategory Page URL to Display Only Posts from that Subcategory?
- Setting the Primary Category for a Post Based on Context
- How can I display image child category in parent
- Limit categories to hierarchal depth of 2
- Custom Taxonomy Isotope Grid – Filter Buttons Not Working
- Shop Category Pages missing s
- ADD DYNAMIC attribute for category to accordion
- How to prevent tag “iframe” from being deleted from the heading description of rubric?
- Unable to add multiple categories to a post in WordPress
- How to display custom fields as table in Woocommerce
- make color of headline depend on category?
- Menu with category 2 category combined
- Some subcategories not working on custom portfolio sort
- How can I make a category function as a page?
- Link For Portfolio Categories
- Displaying Category in sidebar post widget but not in the loop on home
- Create duplicate category page with content variations
- Renaming default category taxonomy?
- Media Categories as Classes on WordPress Gallery Shortcode
- Category names dependent on each other?
- Category Template for Custom Post Type
- Loop Through Categories in Custom Field
- Backend – Categories and Menus conflicts
- get categories the post was in and just been removed from
- Loop through posts of CatA and store value of CatB in separate array
- Highlight posts that belong to current sub category
- How to add an empty entry to masonry?
- How to enable admins/editors to set a featured image for specific category?
- Problem with single posts not showing correct category sidebar
- Multiple Categories under one URL, where ‘Front Page’ is used already
- finding out the top 5 source ( source is a custom taxonomy ), in a given category
- How to display many photo albums related to category
- Modify functions.php to add a term ‘uses-theme’ set to theme name on post save
- Having Trouble With get_category_by_slug In a Custom Function
- WordPress category gives 404 after moving to a different domain
- Create custom Perma link
- How to load/include category templates based on conditionals?
- Why does WordPress append a bullet to my category tag?
- how to implement next/prev within category archive?
- Add product category to post_class
- Function to reference post meta in place of category Woocommerce