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 badges1 Answer
Reset to default 1You 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
评论列表(0条)