Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add excerpt in custom post type in wordpress?

Tags:

wordpress

I created a custom post type in WordPress how I can add custom excerpt add a field in this. custom post type is saved in the same wp_posts table. and Add option show all the fields. But now I want to add custom excerpt field in this. I there any WordPress function to add an excerpt. anyone can help!

like image 474
Harman Cheema Avatar asked Aug 01 '17 11:08

Harman Cheema


2 Answers

Change your support field to this 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) );

like image 144
baiju jha Avatar answered Dec 28 '22 08:12

baiju jha


I hope you have created the custom post type by adding the function register_post_type() in theme function.php file. If yes, you just update your code with 'supports'. Then go to Screen Options and click 'Excerpt'.

$args = array(
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);

register_post_type( 'book', $args );

Or you can also add the following code

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
     add_post_type_support( 'page', 'excerpt' ); //change page with your post type slug.
}
like image 24
Dev Kiran Avatar answered Dec 28 '22 07:12

Dev Kiran