I need to modify the default category that is created by wordpress after the installation. I want to create a new one and modify the existing one after that my theme is activated. Is this possible?
I need to modify the default category that is created by wordpress after the installation. I want to create a new one and modify the existing one after that my theme is activated. Is this possible?
Share Improve this question edited Feb 15, 2020 at 1:58 RiddleMeThis 3,8078 gold badges22 silver badges30 bronze badges asked Feb 14, 2020 at 16:30 sialfasialfa 32910 silver badges29 bronze badges 2- yes, what have you got so far? – RiddleMeThis Commented Feb 14, 2020 at 16:35
- @RiddleMeThis nothing because I don't know if there is an hook or similar to achieve this, this is why I'm asking here. – sialfa Commented Feb 14, 2020 at 19:03
1 Answer
Reset to default 0You 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.