create category on theme setup

Is possible to create some default categories when a custom theme is activated? I mean, when I activate a custom theme,

Is possible to create some default categories when a custom theme is activated? I mean, when I activate a custom theme, I want that some predefined category are created, for example news or info, this because using this way I can load the post directly on the template parts of the theme. Otherwise, if I want to add a custom widget plugin, how I can achieve this? I see many website that are using widgets in footer or in other part of the pages, but I've never used them so I don't know thhe correct way to add this feature on my page or post php files that have this structure:

<?php 

if( have_posts() ): while( have_posts() ): the_post();

the_title();

the_content();

endwhile;
endif;

?>

All the markup are added using shortcodes except for the title or sometimes for the post thumbnail.

Is possible to create some default categories when a custom theme is activated? I mean, when I activate a custom theme, I want that some predefined category are created, for example news or info, this because using this way I can load the post directly on the template parts of the theme. Otherwise, if I want to add a custom widget plugin, how I can achieve this? I see many website that are using widgets in footer or in other part of the pages, but I've never used them so I don't know thhe correct way to add this feature on my page or post php files that have this structure:

<?php 

if( have_posts() ): while( have_posts() ): the_post();

the_title();

the_content();

endwhile;
endif;

?>

All the markup are added using shortcodes except for the title or sometimes for the post thumbnail.

Share Improve this question edited Dec 9, 2019 at 10:47 sialfa asked Dec 8, 2019 at 9:21 sialfasialfa 32910 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the after_setup_theme for this eg:

add_action( 'after_setup_theme', 'custom_add_cat' );

function custom_add_cat() {
    //Create Custom Category
    wp_insert_term(
    'Custom Category', 
    'category', 
    array('slug' => 'custom-category')
    );
}

Read here for more info: https://developer.wordpress/reference/hooks/after_setup_theme/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744925641a4601418.html

相关推荐

  • create category on theme setup

    Is possible to create some default categories when a custom theme is activated? I mean, when I activate a custom theme,

    2天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信