admin管理员组文章数量:1393083
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.
本文标签: phpCreate category after theme setup and modify the default one
版权声明:本文标题:php - Create category after theme setup and modify the default one 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744746763a2622928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论