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
- Prevent Delete Attachment by URL or When Submit
- How to allow users to post only in certain category and hide elements from edit page?
- Enable Comments Box On Custom Post Type
- wp-cli post create & media import issues
- Search results posts_orderby and ID
- How to Restrict Previous & Next Post Link to Posts of Same Category?
- Getting Custom Post Loop to display in Bootstrap 3 column grid
- Pulling in post category and children within category
- Turn On Comments On Custom Post Types in Directory Theme
- Responsive images with custom image size
- Making a custom Pagination for multi page blog post
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- Post categories to pages
- Get user categories with most posts in it
- Editing the default page to show all posts, rather than most recent ones
- Unable to restore from backup – how to obtain old blog posts?
- Post page to display specific category
- Show only one page link in content pagination
- Get Posts Under Custom Taxonomy
- Get attachments for posts that belongs to a specific category
- Prevent additional top level categories but allow more children
- Need help with category listing!
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- Automatically add date to the auto generation of post slug
- Permission issue with custom post type – not added to menu – by plugin
- Duplicate Custom Post Type and Taxonomy Slug
- How could I change my Permalink from blog to custom structure? [closed]
- Categories list into registration form
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Take a received feedback item, turn it into a post
- Getting value from get_post_custom
- WP Admin register taxonomy and post type performance
- Add a custom meta box in the post options that loads some html code in the header
- WP_Query: Mixing category__in and tag__in together
- Static posts page with home.php
- If in_category not working for multiple single.php pages
- Calling Different Custom Post Timestamps in a table
- How can I setup a relationship using categories in WordPress?
- Admin – create custom post status and display above table
- how to show single post in a custom template
- Using ajax on editing a category edit page?
- Related posts by category not working right
- custom post template file not shown, instead all the time 404.php
- How to list recent posts in a wp nav menu?
- Disable sticky option for specific categories
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How to allow visitors to filter posts by multiple taxonomies
- How can I hide tags on a child-category page, if that tag has not been used?
- Show only posts with images and a fixed amount of posts
- date issue with category post retrival
- show custom post type category dropdown sorting result on same page
- Listing Specific Categories from Current Post with Depth
- Custom Post Type Rewrite To Include Parent Page(s)
- How to make multiple sections in home pulling posts category wise?
- How to display two blog categories as separate sections on one page?
- How to create new post content templates for my users?
- Thumbnail & Category link aside post
- How to make the first post in the loop be styled like a “new / featured” post?
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- How do I stop the loop from repeating in my category template?
- get_the_category listing in hierarchial order
- How do I do a page break?
- Is it possible to add/tick a category to a post when it is created?