Adding Excerpts to Pages in WordPress

Being able to display post excerpt is a very useful feature in WordPress. This can also be used to display dynamic content on meta tag for better SEO purpose. On this site, I am also using the excerpt to display the summary of the articles. Specially on the archive pages.

Interestingly, there are no excerpt feature for “Pages”. However, with little effort we can easily add excerpt feature for pages. In this post, I will show you how to enable post excerpt for Pages. So, here we go.

<?php
function add_page_excerpt() {
   add_post_type_support('page','excerpt'); }
add_action('init','add_page_excerpt');
?>

Simply copy and paste this snippet on your theme’s functions.php file and update the page. This should enable the “excerpt” box for your Pages which you can use to write custom page summary. Once you are done, you can easily call “the_excerpt” function on your sit’e meta tags for enhanced SEO.

Now, if you take a look at the function carefully. You can see that I used “add_post_type_support” function to enable excerpt for pages and initialized the function with an “add_action” hook.

I already wrote an article on how to define the length of the excerpt which you may find to be useful and get creative with that.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from HTMLify, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.