In this short example you will learn how to add a custom excerpt to WordPress pages. If you can copy and paste text and know how to work your website’s file manager or FTP, you will be able to implement this code into your WordPress website.
How To Add Custom Code To Your WordPress Website
- Connect to your WordPress website using FTP (You may try out FileZilla for free).
- Once you have connected via FTP, navigate to your WordPress installation.
- Open your theme’s functions.php file with your text editor of choice. This can be found under wp-content > themes > {YOUR ACTIVE CHILD THEME}.
- Copy the code below from line 5 onwards and paste it into your functions.php file (right at the bottom).
- Once this is done save your changes and ensure you overwrite the changes.
<?php
// Add this code to your child theme's functions.php file
function add_excerpt_to_wp_pages() {
add_post_type_support( 'page', 'excerpt' );
}
add_action('init', 'add_excerpt_to_wp_pages');
This will add an excerpt option underneath screen options (found at the top right of the edit page screen) , once selected a meta box will be available below the page content editor.
Photo by
Brandon Morgan on
Unsplash