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
- Where do posts get the sidebar from?
- Set WordPress Default Template
- Adding country tags automatically
- write custom woocommerce templates and forms
- Implement toggle switch for theme options in settings API
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- Query all posts of a custom taxonomy term
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- get current product name in functions.php
- Using a variable in is_page(array())
- Trigger popup in a php if/else statement
- Anyway to output the registration form like the login form with wp_login_form()?
- How do I get current page ID in WordPress customizer file?
- How to get data about category in category.php
- Customizer: Output default value in Customizer CSS
- How to load a template-part based on a url wildcard?
- get post based on category chosen in drop down – The ajax method
- WordPress does not load page.php, return 404.php
- How to use transient in this code for related post?
- How can i upload images in an admin page?
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- get_term_link() returns incorrect url
- Multiple WordPress Menus that will only display all pages
- Creating a related post section based on similar categories
- Set the checkbox as checked by default at options page
- Swapping wp_dropdown_categories function with wp_category_checklist
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Add child pages of parent to navbar PHP
- How can I create a list of page titles from custom meta values?
- Load a page into a div with Ajax
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- Theme Options Page – User Updates Logo
- get_term_link() returns correct – But illogical error-messages disturb
- Converting HTML Template to WordPress Theme
- Proper syntax or method for keeping url in modified isotope / category links
- How to use my style.css file outside of wordpress subdomain?
- Apply different Class for each element in a foreach()
- How to show part of the_content?
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Wp-login appears White Screen, Error: Cannot modify header information
- Filter Select results based on selection
- How to remove the cufon script from Dzonia Lite theme [closed]
- get_the_tags() not iterating through for/while loop, but will with foreach
- get a simple array of all of the term names that exist in all taxonomies
- Hide categories that are not used in the post type
- What is an equivalent of single_cat_title for getting the slug of the category?
- PHP Warning: Attempt to read property “term_id” on bool
- Issue adding sub category programmatically
- How do I add custom bulk actions to multiple custom post types?
- Add_action not working in required file of functions.php
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- how do I get a specific post from a post with a subcategory in WP
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- what is the best practice to add new field to an api route
- WP grandchild categories in nested ul li
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Can’t access variable outside for loop
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- add custom link to wordpress media gallery modal
- How to show single category archive
- Move category description below post list in blog
- Need Help Fixing My Iframes [closed]
- How to pick the default selected value in wordpress dropdown?
- Avoid parallax images hardcoding
- Improve page speed loading using CDN and async or defer attribute
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- How to get original custom taxonomy slug after the slug has been rewritten?
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- post created but no permalink
- selected option if current category is the value
- get_template_part based upon post’s category
- Populate editor with some content of a page with a page template
- how to save selected option in variable for rest api category filter
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Setting default category base on theme activation
- Hide subcategories (widget)
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Get term siblings of current child taxonomy
- Alert Bar section within WP loop is displaying even though there are no posts
- Let Users Choose Post Categories