Wordpress - Add Excerpt Field to Custom Post Types

Robert Valcourt
Jun 16, 2016
Wordpress - Add Excerpt Field to Custom Post Types

If your WordPress theme does not support the excerpt field on custom post types, don't worry! You can add this functionally yourself in minutes. Also, add powerful rich text capabilities to enhance your layouts further.

To make use of this guide, you will need a basic understanding of HTML, PHP and editing WordPress theme files.

Why do you need an excerpt field on custom post types?

Many of the WordPress themes offered today are vibrant, highly functional and easy to use. Sometimes, however, the theme's default programming may not offer you the level of customization you need. For example, perhaps your theme uses a custom post type for services or photos and automatically generates a gateway page for you. The theme may take the first visible content from each content node and use that on the gateway page. I many cases, the theme will truncate the text in a way that you may not like. By adding you own dedicated excerpt field, you have full control over content and layout.

Register the post type to use the WordPress excerpt field

The first thing you will need to do is register the custom post type to receive the excerpt field. To do this, log into your hosting space via FTP.

  • Navigate to the wp-includes folder
  • Open the file marked as post.php
  • Add the following instruction and save:
function wpcodex_add_excerpt_support_for_cpt() {
 add_post_type_support( 'post-type-alias', 'excerpt' );
add_action( 'init', 'wpcodex_add_excerpt_support_for_cpt );

Replace 'post-type-alias' with the alias your theme uses for the post type. You may need to review your theme's documentation to determine the alias.

Edit the WordPress theme template

Next, you will need to edit the template file that the theme uses to generate to automated excerpt. Do not edit the theme template file directly. Copy the template file to your theme's child folder. To learn how to use WordPress child themes, review this WordPress how-to article.

Once you have a working copy of the template file in your theme's child folder, open it and search for the code that generates the automated excerpt. It may look something like this:

<?php post_excerpt(); ?>

Replace this code with:

<?php the_excerpt(); ?>

Now go and open a post in your custom post types section. You will notice the WordPress excerpt field is now available. Add some custom content to it and save. If you replaced the correct code in your template file, you should now be seeing your content live.

Build better layouts with rich text excerpts

Optionally, you can add rich text capabilities to your new excerpt field. Search for and install the Rich Text Excerpts plugin. Once installed, go to the plugin settings page and check the custom post type you are working on. The next time you edit a custom post, you will see all available WordPress rich text controls above the excerpt. Enjoy!

Did this guide help you? Are you making use of your custom excerpts? Let me know in the comments section below.

Made With In Whistler