WordPress presents default category as a setting in Settings -> Writing (though this doesn’t seem to pre-check the checkbox):
The new_to_auto-draft
action will allow you to do things to a new post before the page loads, and does pre-check the checkbox (tested):
add_action( 'new_to_auto-draft', static function ( $post ) {
$default_category_id = 25; // The ID of your default category.
wp_set_object_terms( $post->ID, $default_category_id, 'category' );
} );
Related Posts:
- How can I hook into the post editor title field in order to change the HTML?
- admin_notices not working in post editor
- WordPress hook that gets featured image from direct URL?
- Remove Permalink From Admin Edit Post
- post.php AJAX request not being called when publishing post
- Can we change the hook firing sequence?
- Where can I find a list of WordPress hooks?
- Whats worth using add_action when we can simply use add_filter?
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Hook on trash post
- Adding onload to body
- What is the earliest possible hook for safely using `is_front_page`?
- Send data to 3rd party api with wp_remote_post on wp_login
- How can I log a user out of WordPress before the page loads?
- How to customize the WP admin default help contents
- Admin Post Update Redirection to Posts Screen
- admin_post hook not called
- deactivated_plugin hook: get the name of the plugin
- Is there a hook for user activation (after they click the email confirm)?
- Setcookie works on admin but not front end
- Use latest jQuery in WordPress (admin interface)
- How to hook into user registration process Before user registers
- WP Admin Bar frontend issue with dashicon deregister
- A good way to add a different background image for each page?
- Searching a hook which triggers when deleting a post to get all comments
- add_action for lost_password or modify wp-login.php?action=lostpassword
- Using WPAlchemy metabox values in another metabox
- Add my own function to existing WooCommerce hook
- @wordpress/hooks use to add actions/filters within multiple plugin
- Firing a function AFTER redirect
- How can I customize the upload error message in WordPress?
- Why is save_post hook being called twice despite all my efforts?
- What’s hook to use immediately after a user is authentcated [duplicate]
- Hook before posting via JSON REST API
- add_action for unknown custom post types
- How to prevent double execution of do_action statements
- When is the {$new_status}_{$post->post_type} transition hook fired?
- TinyMCE as comment editor – encoding issues
- Hook to change Logout url
- How to exclude a list of specific category in category widget in new post admin screen?
- Method to find a hook
- Understanding WP
- Get post or page id early
- Looking for a hook for post.php
- Executing Arbitrary Code at a Specific URL without Creating a Post or Page?
- Update a costume wp_usermeta key back to 0 every 24hours (time can be specified as needed)
- Trigger a custom function when option are saved in admin area
- customize_controls_enqueue_scripts doesn’t fire from within my plugin
- Save User Meta Email Address in Lowercase
- When are wp redirect methods safe to hook?
- Problems with WP_List_Table and hooks
- WooCommerce single product page quantity description [closed]
- Execute JavaScript in WordPress Hook
- How to cancel the trash action inside wp_trash_post
- wp_insert_post_data hook should be called before updating db but isn’t
- How to display message (with switch_theme hook) after deactivating My theme?
- Clicking Add New button for custom taxonomy only moves element
- load-* hook for dashboard
- What conditions must be met in order to upload .zip file to a multisite WordPress installation?
- How to hook code in ?
- wp_enqueue_script before wp_head
- Is it possible to add the_content filter upon login?
- Why can’t a custom postype be registered with “admin_init” hook?
- Use an array of page template slugs and $hook
- wp_logout hook never triggered
- add short description under price
- How do I use pre_option_{option_name} correctly?
- WordPress media library allow uploading fake file
- What hook do I use if I want to update a user profile field when a new user is created?
- How to add custom tab page in backend?
- Add html code in admin page
- Hooking dynamic/variable named hook in all cases
- What hook to add at start of WordPress load
- Knowing if a post is sticky in the ‘save_post’ action. Where do I have to hook?
- How to read and write session data?
- Count when a post of a custom post type is deleted and store it in a theme option
- Intercept loading of a certain page
- Add content in cpt archive page
- Creating custom post on registration in wordpress?
- Display custom user profile fields in wordpress
- profile_update not supplying old data
- Output Redirect Headers on Admin Dashboard Page
- add_image_size not working with after_switch_theme
- wordpress hooks
- Check when a setting has been changed
- add extra parameter in default hook in wordpress
- Exclude WooCommerce terminations from YOAST
- Hook triggered twice in a Woocommerce single product page
- set_post_format called after wp_update_post when using bulk edit?
- add hook restricted only to either plugins or themes?
- How to hook watchdog script for existence of a WP page?
- addaction hook cause redirection problem
- Getting all post/page IDs related to a soon-to-be-deleted tag/cat
- Hooking get_pages()
- Fire a hook programmatically
- Transform .wp-video to the native video player of the browser
- How do I override the user’s input when updating a custom post type’s permalink?
- How to add a new link to the default register form’s footer links?
- How to use the password_reset hook to validate new password and display error
- Get post ID before add_theme_support