How to change your default wordpress post category & post type?
Answer / 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 |
Explain me what are the custom fields in wordpress? How to display it?
What is a taxonomy in wordpress?
How do I set up a subdomain?
How do I start a blog from scratch?
How do you create a page in wordpress?
How do you create a blog page?
What is wordpress good for?
What is a template on a website?
Can I monetize my wix blog?
What are meta-tags in wordpress?
Is a website on wordpress safe and secure?
Where is wordpress database stored?