{"id":1080,"date":"2018-01-26T09:26:55","date_gmt":"2018-01-26T09:26:55","guid":{"rendered":"https:\/\/firstsiteguide.com-excerpts\/"},"modified":"2023-10-04T09:25:08","modified_gmt":"2023-10-04T09:25:08","slug":"wordpress-excerpts","status":"publish","type":"post","link":"https:\/\/firstsiteguide.com\/wordpress-excerpts\/","title":{"rendered":"How to Control Excerpts in WordPress","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"

An excerpt is a post summary that is being used to describe your article in a few short sentences. Those descriptions are a great way of letting your visitors see what\u2019s the post about and decide if they\u2019re interested in reading the rest of it before clicking the button. Also, it is an excellent tool for RSS readers.<\/p>\n\n\n\n

In WordPress, excerpts can be manual or automatic, and they\u2019re slightly different from teasers (text before <–more–> tag) just because WordPress is handling them differently. If you don\u2019t write your own excerpt, WordPress will make a summary automatically and take first 55 words from your post.<\/p>\n\n\n\n

In this article, we are about to show you how to control excerpts in WordPress. <\/p>\n\n\n\n

How to change excerpt length in WordPress<\/h2>\n\n\n\n

If you are new to WordPress<\/a> and now you\u2019re trying to find your own excerpt box where you want to write a manual summary, you have probably found none. That\u2019s because excerpts are hidden by default. To make the textbox visible, while you are editing a post or writing a new one, click on \u201cScreen Options\u201d<\/em> which can be found on top of the page where you have to check \u201cExcerpts\u201d. Now you\u2019re ready to scroll under your post and write your excerpt.<\/p>\n\n\n\n

But as you can see, there is no option which would simply change the length of an excerpt. That\u2019s probably one of the reasons why you\u2019re reading this article, and in the next few lines, we\u2019re about to show you a quick and simple way of doing that.<\/p>\n\n\n\n

    \n
  1. Go to Appearance-> Editor<\/em><\/li>\n\n\n\n
  2. On the right side, find function.php file or open the file from your FTP client<\/li>\n\n\n\n
  3. Copy and paste the following function:<\/li>\n<\/ol>\n\n\n
    \n \n\n
    function my_excerpt_length($length) {
    return 110;
    }

    add_filter('excerpt_length', 'my_excerpt_length');<\/pre>\n\n<\/div>\n\n\n
    <\/pre>\n\n\n\n
      \n
    1. Save changes after which your excerpts will have a limit of 110 instead 55 words<\/li>\n<\/ol>\n\n\n\n

      Of course, you are free to change the number to any integer you want. But remember we\u2019re talking about summaries \u2013 you don\u2019t want your summary to be too short, but there\u2019s no need for exaggerating. You can always put a “read more” link<\/a> after each excerpt.<\/p>\n\n\n\n

      If you want even more control over your excerpts, you should consider Advanced Excerpt plugin<\/a> which is capable of doing the same job with some extra features, plus, you won\u2019t have to deal with the code and PHP files.<\/p>\n\n\n\n

      Change default excerpt length for different categories<\/h2>\n\n\n\n

      After some time spent on your WordPress blog<\/a>, some categories might require more words in excerpts and some will need shorter ones. So, let us show you how to change the length of the category excerpt.<\/p>\n\n\n\n

      The first example will let you choose one category for which you want to set a different excerpt length. Select that category, define the number of words for its excerpt and the number of words for all other categories\u2019 excerpt:<\/p>\n\n\n\n

        \n
      1. Open functions.php<\/li>\n\n\n\n
      2. Copy and paste this function:<\/li>\n<\/ol>\n\n\n
        \n \n\n
        function excerpt_length_category( $length ) {\nif ( in_category( 'Reviews' ) ) {\nreturn 20;\n} else {\nreturn 60;\n}\n}\nadd_filter( 'excerpt_length', \n'excerpt_length_category' );<\/pre>\n\n<\/div>\n\n\n
        <\/pre>\n\n\n\n
          \n
        1. Change category name on the 2nd line<\/li>\n\n\n\n
        2. Change the length of excerpts (number of words) for that category on line #3<\/li>\n\n\n\n
        3. Change length of all other categories on line #5<\/li>\n\n\n\n
        4. Save changes<\/li>\n<\/ol>\n\n\n\n

          While this will be more than enough in order to change excerpt length for that one category that bothers you, it won\u2019t help you much if you need to define the length for several categories at once<\/strong>. In that case, you will be needing the following:<\/p>\n\n\n

          \n \n\n
          function excerpt_length_category( $length ) {\nif ( in_category( 'Review' ) ) {\nreturn 35;\n} elseif ( in_category( array( 'News', \n'Videos', 'Editorial' ) ) ) {\nreturn 60;\n} else {\nreturn 55;\n}\n}\nadd_filter( 'excerpt_length', \n'excerpt_length_category' );<\/pre>\n\n<\/div>\n\n\n
          <\/pre>\n\n\n\n

          This function will allow you to set different excerpt lengths for different categories and still let you choose the default one.<\/p>\n\n\n\n

          Add a “Read More” link to the end of an excerpt<\/h2>\n\n\n\n

          Instead of displaying the entire post on your homepage, excerpts allow you to show only a part of it which can make the user interested in the article.<\/p>\n\n\n\n

          After users see the title, image, and an excerpt of your post, you need to inform them that they can read more about the topic by following the link to your article. If you ask us, a featured image<\/a> should always lead to the main article, but you should also allow your readers to follow the \u201cRead More\u201d link or a button.<\/p>\n\n\n

          \n
          \"Add<\/figure><\/div>\n\n\n

          <\/p>\n\n\n\n

          If your WordPress theme<\/a> doesn\u2019t have the feature already included, you should create one for yourself. In this part of the tutorial, we\u2019re about to show you how to quickly add a \u201cRead More\u201d link at the end of each excerpt:<\/p>\n\n\n\n

            \n
          1. Open functions.php<\/li>\n\n\n\n
          2. Copy and paste the code:<\/li>\n<\/ol>\n\n\n
            \n \n\n
            function excerpt_readmore($more) {\nreturn '... <a href=\"'. get_permalink($post->ID) . \n'\" class=\"readmore\">' . 'Read More' . '<\/a>';\n}\n\nadd_filter('excerpt_more', 'excerpt_readmore');<\/pre>\n\n<\/div>\n\n\n
            <\/pre>\n\n\n\n
              \n
            1. Change the text if you want to<\/li>\n\n\n\n
            2. Add a different class if you want to style the link differently<\/li>\n\n\n\n
            3. Save changes<\/li>\n<\/ol>\n\n\n\n

              That\u2019s actually all there is. After you\u2019ve have saved the changes, each and every excerpt on your WordPress powered website will now get a \u201cRead More\u201d text (or whatever did you write in the code above) with a link to the original post attached to it automatically.<\/p>\n\n\n\n

              You can check out the result by opening your homepage, blogroll or wherever you\u2019re displaying post\u2019s excerpts.<\/p>\n\n\n\n

              If you would like to have more control over excerpts or you don\u2019t like messing around with the custom functions, you should take a look at Advanced Excerpt plugin<\/a>.<\/p>\n\n\n\n

              Show excerpts in WordPress pages<\/h2>\n\n\n\n

              By default, WordPress doesn\u2019t include excerpts in pages. That\u2019s quite reasonable since pages are made to be different than posts. But in some cases, you\u2019ll need excerpts in your pages as well.<\/p>\n\n\n\n

              Since there is no easy way of allowing this, i.e., there is no checkbox which you can simply click to enable excerpts for pages, we will show you the second easiest way of doing that.<\/p>\n\n\n\n

              No, you won\u2019t be needing a plugin, nor you\u2019ll have to go into detailed setups. In the following lines, we will show you a really short function which will do the job for you.<\/p>\n\n\n\n

              Show Excerpts in pages:<\/h3>\n\n\n\n
                \n
              1. Open functions.php<\/li>\n\n\n\n
              2. Copy and paste the code snippet:<\/li>\n<\/ol>\n\n\n
                \n \n\n
                function wploop_pages_excerpt() {
                add_post_type_support( 'page', 'excerpt' );
                }
                add_action( 'init', ' wploop_pages_excerpt' );<\/pre>\n\n<\/div>\n\n\n
                <\/pre>\n\n\n\n
                  \n
                1. Save changes<\/li>\n<\/ol>\n\n\n\n

                  It\u2019s definitely not as simple as clicking the checkbox, but it wasn\u2019t much harder than that, wasn\u2019t it? Now that you\u2019re done with copying the code, you can navigate to any page to test the feature.<\/p>\n\n\n\n

                  Most probably you won\u2019t have the excerpt shown below the page content right away. But don\u2019t worry \u2013 you only need to allow excerpt to be displayed on the page:<\/p>\n\n\n\n

                    \n
                  1. Scroll on top of the page<\/li>\n\n\n\n
                  2. Find \u201cScreen options\u201d tab and open it<\/li>\n\n\n\n
                  3. Find the \u201cExcerpt\u201d checkbox and mark it<\/li>\n<\/ol>\n\n\n\n

                    Well, it seems like there was checkbox included in the process all the way!<\/p>\n\n\n\n

                    You can now scroll down and write an excerpt of your page. Code snippets like this one can really help a lot, right?<\/p>\n\n\n\n

                    Control WordPress excerpts with Advanced Excerpt plugin<\/h2>\n\n\n\n

                    PRICE: <\/strong>Free<\/a><\/p>\n\n\n

                    \n
                    \"Advanced<\/figure><\/div>\n\n\n

                    <\/p>\n\n\n\n

                    After you install and activate this free plugin, there are several options you can choose from to control your excerpts:<\/p>\n\n\n\n