You can use wp_update_term to modify terms (even the default uncategorized) and wp_insert_term to update existing terms.
Here is a basic example that should get you there.
function add_category(){
// Update Uncategorized Category (1)
wp_update_term(
1,
'category',
array(
'name' => 'New Category Name',
'slug' => 'new-category-slug'
)
);
// Insert New Category
if(!term_exists('another-category')) {
wp_insert_term(
'Another Category',
'category',
array(
'slug' => 'another-category'
)
);
}
}
add_action('after_setup_theme', 'add_category');
This is tested and works.
Related Posts:
- How do I edit the terms output args or array data?
- Custom HTML structure in wp_list_categories
- List all categories but exclude current post category on single post page
- Problems with function on function.php
- Custom category code not showing all posts
- Grab posts by multiple categories
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Include Parent Term in wp_list_categories
- Get all categories post is not in
- WordPress custom taxonomy
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- WordPress using get_term to retreive slug not working as expected
- Incomplete term slugs output from a foreach loop with get_the_terms
- WordPress Themes and PHP unit
- What does the token %1$s in WordPress represent [closed]
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- Dynamically change feature image in customiser
- Display all posts in current category
- category not display in word press grammatically
- Design view breaking on Pages
- Adjust the results quantity for Search Results page pagination
- How to display related posts from parent category
- How can I set custom order use this function
- Is it possible to use the featured image of a page as a css background without inlining?
- How do I translate this string – PHP syntax question
- Site Health : An active PHP session was detected
- Check if Product is in a Specific Category in Functions.php
- How to display recent posts on home page with custom HTML
- using add_action for a header hook that has an additional parameter
- get_the_terms – only top level
- Category Thumbnail Display – How to display ONLY the main Category
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- Set the checkbox as checked by default at options page
- Swapping wp_dropdown_categories function with wp_category_checklist
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- how to save selected option in variable for rest api category filter
- How to get post’s current parent term ID?
- How to disable controls in theme customizer?
- how to show only specific category for a template
- What does this mean in wordpress? Easy question
- Show About and Contact Us page when they’re clicked in the top menu.
- Is There A Way To Make Theme Files Accept Shortcodes?
- WordPress import media error
- Displaying posts based on category
- Get categories names as an array to use it in theme settings
- Hide Heading if ACF Field is empty
- How to get the last category name of a child category?
- How do I get the content excerpt of the recent post?
- Save Custom CSS file in the upload folder dynamically?
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- How to separate categories with commas?
- Getting posts to exclude from array
- Show all tags within a category?
- home.php show blog posts as grid view
- Custom post type permalinks do not appear using the link functions
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- Alphabetically Ordered Category in WordPress
- Loading Posts & Category with Ajax
- How to get current category
- Using bloginfo and divs inside a php file
- Get css class of menu item in custom menu structure
- How to organize functions.php content
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Search page results conflicting logic – Search result caching?
- Show parent categories of the current category
- How to check if a category has a parent and child categories?
- Get category id when SEO URL is turned on
- Trying to display terms from custom taxonomy within function
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- Display Sibling WooCommerce Product Categories on Archive Page
- For some time, some of my pages do not display the content anymore. Any idea where this could be coming from?
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- display the months of a specific category
- List sub categories and corresponding posts of a parent category
- Dropdown category field inside repeatable metabox
- How to extend SelectControl with data from my theme
- excep tonly one css, don’t load any css
- How to use wp_get_attachment_image or wp_get_attachment_image_src instead of $instance[‘single_feature_image_uri’]
- How to Link to category titles if it is in the single post content?
- How can i show specific Category List?
- How to show category just on specific pages?
- Proper use of Output Buffer for a whole php clas
- wp_set_object_terms returns 500 error when called through AJAX function
- How to filter specific element of an array in wordpress/php?
- CSS loading as empty file in Custom Theme
- How can I customize a WordPress theme before it’s downloaded?
- List categories assigned to a post
- Unable to get Post Category Name and URL
- Trying send mail from Theme page
- Trying to see if page is category or single and displaying title with appropriate heading tag
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Shortcode working in page.php but not in category.php in wordpress
- category & sub category order issues in wordpress
- Adding a Sub Menu Options Page WP Backend Menu. Whats wrong with my code?
- How can a ‘scripts’ directory be hooked into wp_head();?
- How to create categories out of a list of words?
- WP and Laravel integration (Updated) [closed]
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- Add default block css when the block has been added with php?