the content_save_pre filter. It checks the post type of the current post and ensures that the content field is not empty. If the content field is empty, the function calls wp_die() to display an error message and stop the post from being saved.
Note: Make sure to replace “custom_post_type” with the actual name of your custom post type. Also, you can modify the error message to fit your needs.
add_filter( 'content_save_pre', 'validate_custom_post_type_content' );
function validate_custom_post_type_content( $content ) {
global $post;
if ( 'custom_post_type' === $post->post_type && empty( $content ) ) {
wp_die( __( 'The content field is required for this custom post type. Please enter some content and try again.' ) );
}
return $content;
}
Related Posts:
- How to load a new template page according to a particular URL?
- Should I use RIPS tool to test my themes and plugins?
- How to Build a Movie Library in WordPress 3.x
- Workflow and best practice for documentation [closed]
- How to get current post user id
- Redirect to another page using contact form 7? [closed]
- How do I combine a theme with a plugin
- How to write “alt” tag in image for wordpress code?
- Don’t load the theme for a page FROM a plugin EDITED
- Extending a theme: build new features as plugin or core modules?
- How do you create a re-useable HTML fragment in wordpress
- How to override any plugin file in the child theme
- when i activate my WordPress plugin cannot see customizer options or preview
- how to add custom css at top above all css file for specific url
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- Breadcrumb is not generating the correct post page url
- Site is setup statically – how to make it content managable?
- How to escape html code?
- How to create new title and its description inside a section in WP Customizer?
- Tips for using WordPress as a CMS? [closed]
- Custom Post Type Templates from Plugin Folder?
- Custom media upload content for inserting custom post shortcode
- Redesigning Custom Post Type “Add New” page
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- Creating a default Custom Post Template that a Theme can override
- What is the correct way for a theme to support plugin UIs?
- How to call “page specific menu items” in template [closed]
- Update Multiple Post Meta for the Same Post In One call?
- Function to activate WordPress theme inside a plugin
- Which functions in theme or plugin load first
- How do I make my wordpress page more friendly for mobile viewers?
- How to make my plugin theme-independent?
- Check javascript file Proper way in functions.php
- How to get the custom page get_permalink?
- Updating post meta for custom post types
- Themes VS Plugins [duplicate]
- remove custom taxonomy metabox form custom post type
- Custom Post Type Statuses
- Autoload via composer in plugin interference
- Is there a quick way to inject i18n domain into theme/plugin files?
- Get image URL from media library in input
- Display future posts?
- Override the core function locate_template
- Way to hook into a sidebar call to replace it with a custom sidebar
- Having separate plugins and themes folder for multi-site setup
- How can I get full attachment url from wp_get_attachment_metadata?
- Translating plugin inside the theme [closed]
- unzip a folder on specific location and delete the zip file
- gallery option is not available in media upload box in costum theme option page
- Why are some of my thumbnails not being generated?
- Why is the Settings API is not saving my array of options
- Include Max mega menu Plugin into theme
- How to integrate plugin in WordPress theme
- add_action in functions.php, do_action in plugin?
- wordpress theme backend admin only
- How does WP handle multiple matching rewrite rules?
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- How to use get_theme_mod in gutenberg editor wordpress?
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Reusable functions and tools (Framework)
- Different UI in WordPress
- The problem with WordPress Importer
- Is it possible to create Custom Post plug-in?
- All of my custom posttypes are 404’ing
- Display post lists in 2nd paragraph
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Making a Template for a CPT created by a plugin
- how to add a button next to the wordpress view button?
- Plugin-generated pages use Not Found or Pages Archive templates?
- Is there any kind of theme on WordPress to sell my own movies?
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- get_option include in my adsense
- Disqus plugin outputs script as literal text
- Making a Custom Post Type Publish Loop
- How to get current template file used by WordPress?
- Is an Office a custom post type [closed]
- How can I make a website with dynamic features with wordpress?
- How to generate a responsive output from plugin?
- How to work email subscribe in WordPress?
- How to create post comparison in wordpress
- How to add image for custom taxonomy
- Javascript as Jquery Function Call?
- Integrating WordPress Content into a jQuery Slider
- Editing a theme
- manage_{taxonomy}_custom_column not working
- how to make wordpress remember my choice
- How to Enfroce Domain Licensing Limits? [closed]
- Meta box not displaying on the plugin page
- add_meta_box showing blank screen in my page
- Wrong block appender button showing
- How to create an Info Box on WordPress [closed]
- How to access the page without registering in wordpress
- CPT template is not being automatically used single post pages
- What are Seeds? [closed]
- public custom posts not showing in my wordpress plugin
- How to provide page_template path in custom plugin using WordPress
- Frontend Enqueued Files in the Backend
- Include theme header and footer in custom plugin