Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to change your default wordpress post category & post type?

Answer Posted / Rishabh

To modify the default post category or post type in WordPress, you'll need to edit the functions.php file for your active theme. Here's an example of how to set a custom default category:nn```phpn// Set a custom default category IDndefine('DEFAULT_CATEGORY', 1);nn// Function to create or get the default category if it doesn't existnfunction my_default_category() {n return (int) get_cat_by_slug(get_option('default_category'));n}nn// Filter the default category ID before a new post is createdndefine('pre_post_updated', 'my_set_default_category');nadd_action('pre_post_updated', 'my_set_default_category');nfunction my_set_default_category($post) {n if (empty($post->ID)) return; // Ignore new posts without an IDnn // Get the default category IDndefined('DEFAULT_CATEGORY') or define('DEFAULT_CATEGORY', 1);n $default_category = my_default_category();nn // Set the default category for the postnwp_set_post_categories($post, array($default_category));n}n```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How much is the wordpress business plan?

155


Tell me how do I redirect users back to my blog's main page after they login?

198


Do you know what is the current version of wordpress?

187