I see that I can use wp_insert_category, but how can I call this function automatically on theme activation?
Okay, l can use the functions.php file by the looks of it.
Right, I’ve got this in my functions.php file and I was expecting it to insert the category on theme activation, but it isn’t doing so. Any ideas why anyone?
Thanks.
<?php
function my_activation_settings($theme)
{
if ( 'My Theme' == $theme )
{
$my_cat = array('cat_name' => 'My Cat', 'category_description' => '', 'category_nicename' => 'my-cat', 'category_parent' => '');
$my_cat_id = wp_insert_category($my_cat);
}
return;
}
add_action('switch_theme', 'my_activation_settings');
?>
Anyone out there? I’m trying this now.
Adding this to the functions.php file
wp_create_category(‘My category name’);
causes this error when I try and browse the Themes page in admin.
The website encountered an error while retrieving http://localhost:8888/mysite/wp-admin/themes.php. It may be down for maintenance or configured incorrectly.
I’ve managed to get posts creating fine in functions.php but categories just don’t want to play!
Please help.
Found this, seems to do the job.
$arg = array('description' => "my description", 'parent' => "cat_ID");
$new_cat_id = wp_insert_term("cat name", "category", $arg);