This will default the excerpt value in your custom post type only for new posts:
add_filter( 'default_excerpt', 'smyles_default_custom_post_excerpt', 10, 2 );
/**
* Default Excerpt for Custom Post Type
*
* @param string $post_excerpt Default post excerpt.
* @param WP_Post $post Post object.
*
* @return string
*
*/
function smyles_default_custom_post_excerpt( $post_excerpt, $post ){
if( $post && $post->post_type === 'mycustomposttype' && ! $post->post_parent ){
return '[mycustomshortcode]';
}
return $post_excerpt;
}
The check for $post->post_parent
checks the parent, if it is a “child” post, the value will be different than 0
which means it’s the parent post
Related Posts:
- Excerpt function for any content
- Excerpt length: get first paragraph
- How come Featured Image isn’t showing up in my Custom Post Type?
- How to use a custom post type archive as front page?
- How to remove “read more” link from custom post type excerpt
- Set posts of a custom post type to be private by default?
- How do I filter the excerpt metabox description in admin?
- expire wordpress user posts
- Forcing all posts associated with a custom post type to be private
- How can I add dropdown widget/box to admin post page?
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- Best way to style first post differently?
- if && problems with transition_post_status
- custom post type upcoming post and past post
- Add multiple custom post types in functions.php, but only one custom post type show in dashboard
- Beginner question: Accessing functions.php through admin web interface in order to import custom post types?
- Add $more_link_text parameter to the_excerpt()
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- Need functionality with all post list available at edit.php
- Remove default post types on all sites except primary blog. WPMU
- How would I create a shortcode to display a custom post within a page or regular post?
- GravityForm: Populate Dropdown with custom post type [closed]
- Custom Post Types relationships
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Filter categories of posts with checkboxes
- Copy custom field value to post title
- Insert HTML inside link in a walker
- WooCommerce product search titles only
- Remove standard meta boxes from custom taxonomy
- What’s the difference between same wp functions get_posts(); functions in different form?
- Display custom fields on post excerpt or teaser
- Show category ID on custom post type
- Custom Post Type with Templates using Meta Boxes?
- Can I list a custom post type within another custom post type in the admin area?
- Set URL link to featured image of custom post type
- Change CPT archive title
- AJAX load more for different custom post type loops
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- create a new page from a custom post type similar to an authors page
- Cannot save CPT meta box
- next_/previous_post_link() `in_same_category` appears to fail when true
- Want to be able to sign up subscribers as authors
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- categories should be available across all custom post types
- Warning: Invalid argument supplied for foreach() in post.php [closed]
- Post-thumbnail only for specific post-types?
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Enable taxonomies by post type in an array of CPTs
- custom post for slider
- Navigate posts with different post type that are in the same categories
- Page Template Dropdown For Custom Post Types
- Show Custom Message in WordPress Admin
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- providing access to post_id or post inside functions.php
- WordPress notification if new post published
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Get post format
- post_content is stripping HTML when adding a new post? [closed]
- Shortcode to return single custom post based on post taxonomy
- Template code to split a post and print a custom field?
- Send post changes to set email addresses (not users or subscribers)
- Function to limit number of custom post types on homepage – TwentyTen
- Foreach loop returning more than one item when querying taxonomy
- Post visibility option to theme front-end for author to select?
- display custom portfolio tags
- display custom post on separate page
- Post type Echo code is repeating on homepage
- new post-type how do i retain the plugins on my sidebar?
- Custom Post Type Dashboard Tab not displaying any posts
- php dynamic content inside shortcode
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- Check that a slug is present in the get_terms request
- Assigning categories to custom post types via a front-end form; only works for native post type
- Move to trash custom post type post after ACF Date Picker date is older than today
- From CPT Custom Loop into Shortcode?
- Create posts inside CPT post
- Load custom post type with ID in a shortcode
- How to assign post to category
- Using get_post_type with a custom URL format?
- If thumbnail image else post title
- $_SESSION Not working after X amount of page views
- Different Configuration for the_excerpt()
- Keep custom read more link on the same line as excerpt text
- WordPress page not showing up – replaced with last 10 posts?
- Custom permalink rewrite rules – how do I fix this?
- Post that populates itself (almost) automatically using data from imported excel file
- How to mark posts as visited
- can’t see categories in appearance-menu-categories
- Excerpts and Custom Post Types
- erase post excerpt limitation [×]
- Excerpt for each post type and for is_front_page
- send email to all registered users when post expires
- Comments are not working on Custom Post Type
- add_rewrite_rule not working with custom post type
- wordpress category form fields in popup
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs