Add Snippet To Project
Are you looking to enable page excerpts on your WordPress website? By default, WordPress only allows you to add excerpts to blog posts. However, with a few simple steps, you can enable page excerpts as well. In this article, we’ll guide you through the process of enabling page excerpts in WordPress, giving you more flexibility and control over how your website displays content.
function wpturbo_enable_page_excerpt() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'wpturbo_enable_page_excerpt' );
The code snippet provided enables the excerpt feature for pages in WordPress. By default, the excerpt feature is only available for posts, but with this snippet, we can extend it to pages as well.
The wpturbo_enable_page_excerpt()
function is created to add support for the excerpt feature to the page post type. Inside the function, we use the add_post_type_support()
function to add the ‘excerpt’ support to the ‘page’ post type.
The add_post_type_support()
function takes two parameters: the first parameter is the post type to add support for, which in our case is ‘page’, and the second parameter is the feature to add support for, which is ‘excerpt’.
To ensure that the wpturbo_enable_page_excerpt()
function is executed at the appropriate time, we use the add_action()
function with the ‘init’ hook. The ‘init’ hook is fired when WordPress initializes and is the ideal time to add support for page excerpts.
Once the code snippet is added to the theme’s functions.php file or a custom plugin, the excerpt feature will be enabled for pages. This will allow users to add an excerpt for each page, which can be useful for displaying a summary or teaser of the page’s content in various listing views.