default_content runs when a post is loaded into the editor, actually. You can check for categories when the post is saved, but you’d want the save_post hook, probably. You want to check the $_REQUEST global.
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
global $_REQUEST;
if (isset($_REQUEST['post_category']) && in_array($some_category_id,$_REQUEST['post_category'])) {
$content = "My html content.";
}
return $content;
}
… assuming no syntax errors. 🙂
You probably also want to check if the post_content is empty and insert only it is.
Related Posts:
- Add default content to post (for specific category)
- Setting Custom Sort Order of Posts within a Category
- How to change the layout and styling of posts according to their category in WordPress?
- Show One Category on Post
- Add custom field to category of custom post type
- Do I use custom post type or something else?
- Custom Theme Want To Remove One Category From All Displays
- Edit custom post type admin menu link
- Deleted category by mistake, all posts now have categorized category. Can i revert that?
- How can i limit the number of posts created per category?
- WordPress custom Query for Posts in Category display posts multiple times
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Set Default Category to Username
- Best Way to Add UnEditable HTML to Posts
- if in category but only with post meta
- How to call posts under a specific category on static front page?
- Static pages not working
- Hide parts of the post content after typing it’s name or searching it by category
- How to display only one category in a custom post type?
- Can I style single post that are in multiple catergories?
- Custom post styling per category?
- Show custom post category for single post
- Add Categories To Custom Post
- How do I set content in my pages so that it remains permanent while blog posts are added below?
- Nothing appears using get_the_excerpt() in category.php
- Static text above category page
- Show a Category Specific Info Box
- Display ONLY Latest Post From Several Categories
- Taxonomy Category category.php not working
- Post’s arent displaying
- Only show posts belonging to multiple cateogries at same time
- Notify/check if the content of a custom gutenberg block has changed on save_post
- I have a website issue I am trying to resolve
- How to add a ‘News’ section to specific posts in WordPress
- how to create a category with wp_insert_post and post_category
- Get Category in save_post Hook
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- Show post count in custom taxonomy page
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Create/Set Category as Title of Post
- How to distinguish pages created by woocommerce?
- Exclude posts in a category on one page but show those posts on a different page
- Hide or remove custom post status
- Template for displaying CPT / Taxonomy URL issues
- Multiple posts in one page
- How to create a button to filter posts (list) by meta value
- Put page on Archived statut after end of publication date
- Why do I have categories with duplicate slugs?
- How to display related post from same category in single.php
- WordPress the_category(); only works with message-posts not with project posts, how do I specify project categories?
- Is there a way to save different data when USER interacts with the same POST?
- How to add a block to a category page?
- post and page and custom post type
- How to display particular categorie’s post which associated to specific user?
- Please I want to prefix my WP posts title according to each category
- Display Specific Categories posts on the home page
- Post relationships/nesting
- insert post fails after multiple postings
- delete post hook not being fired when deling in wordpress dashboard admin
- Manual Scheduler For Custom Post Type
- Excluding category from post navigation in WordPress?
- Save All Post Permalink From A Specific Category into a .txt file
- WordPress Delete Users from backend doesn’t work
- Custom Post Type Rewrite URL
- I want to show recent post according to category of the post in single.php?
- Limit amount of categories displayed in a post
- How to make a page show posts only from specific categories without editing php files
- show image gallery in archives or category page
- Dev and prod on the same database- dev version active for IOS
- Is it possible to make a custom post that adds multiple pages?
- Custom Post Types and Broken Permalinks
- show only one category and filter by tag
- Page with Category Returning 1
- The first post appears twice
- How to delete/customize imported demo content from a theme or add my own?
- Automatic Table of contents with categories and posts
- Code to display random ordered posts in Categories across pages [duplicate]
- More Than 50K Categories and WordPress Admin Panel Stop Showing Categories and Posts
- Loop through taxonomies and loop through their terms (Newbie question)
- Get posts from category from custom query
- Re-order Category Meta-data
- My posts page is missing the page title
- Hiding title of selected post without plugins
- AJAX load more posts not using correct category and repeating the same few posts
- Category posts show on local install, they do not show on live server
- get current index of post content in category page
- Category and Posts in front page
- How to show category image if no featured image is set?
- Allow registering user to select post category when signing up to blog
- How can I exclude only a specific sub category post from category display?
- Customizing URL slugs of Custom Post Type and Taxonomy make posts/pages 404
- Post Category link is same with Page link
- Get 5 most recent categories
- how to print total number of posts filtered by category?
- Get a list of categories that are related to posts
- How to show posts ordered by random [duplicate]
- How can change header text in post careate/edit form
- How to Get Position of a Post from a category and tag
- Dynamically load posts based on category
- How to run select query of post with category and tags?