• My site has always used Automatic Excerpts and today I had to introduce Manual Excerpts in order to use some Mail Chimp functionality. However, I want to always use Automatic Excerpts on my WordPress site and Manual Excerpts overwrite the Automatic Excerpts.

    So my question: How can I tell WordPress to use Automatic Excerpts over Manual Excerpts?

    P.S. I would link the site, but it is set to private access at the moment.

    • This topic was modified 6 years, 7 months ago by frankg26.
Viewing 8 replies - 1 through 8 (of 8 total)
  • It’s not a setting. Each post will show the manual excerpt if it exists, and if it doesn’t, one will be generated.

    Thread Starter frankg26

    (@frankg26)

    I am aware that already, but is there a way (even if its through code) to overwrite WordPress default functionality and use Automatic Excerpts

    There’s no need to change code, because generated excerpts is the default.
    Remove the excerpts you entered manually if you don’t want them. Find a different way to do MailChimp if this is a conflict for you.

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    I had to introduce Manual Excerpts in order to use some Mail Chimp functionality

    What plugin are you using for this? I’m wondering if they have a filter you could possibly hook to in order to get this.

    Thread Starter frankg26

    (@frankg26)

    I am not using any plugin, I just filled in the excerpt field that is originally hidden in the Screen Option of the Post editor.

    Moderator bcworkz

    (@bcworkz)

    So you want to always display auto excerpts even though the manual excerpts exist because the manual excerpts serve another necessary purpose? This is possible, but the solution is partly theme dependent. What theme are you using? Or what code is your theme currently using to output excerpts?

    Thread Starter frankg26

    (@frankg26)

    That is correct, manual excerpts exist to serve another purpose. However the excerpts I want to display are the auto generated ones. I use a an internal theme which was created by a contractor, but he cherry picked out components of the Twenty Seventeen and Twenty Sixteen themes.

    My understanding is that the function wp_trim_excerpt() (found in the formatting.php file according to developer.www.ads-software.com) only creates the auto excerpt if there is no manual excerpt. I am now wondering if I can modify this function, so that it always generates an auto excerpt.

    I am comfortable changing the code that was made from the contractor. But I get the vibe that this is WordPress standard functionality and concern that changing it will affect other areas of the site. Hence, why I preferred to ask about it before touching anything in the code.

    • This reply was modified 6 years, 7 months ago by frankg26.
    Moderator bcworkz

    (@bcworkz)

    OK, twentyseventeen and twentysixteen uses both the_content() and the_excerpt() on different templates under different circumstances. Complicating what happens is if you make use of the <!–more–> tag in content. the_excerpt() naturally only shows excerpts, from the manual field if available, auto generated if not. the_content() works like the_excerpt() on index and archive pages, but shows full content on single pages.

    It’s OK to change template code (any theme code actually) of custom developed themes. It’s not OK to change core WP code, and ill advised to change published theme templates or code. You could replace the function calls on a template with functions of your own design. Another alternative is to make use of filters that go with each WP function: “the_excerpt” and “the_content”. Your filter callback is passed the normal output. What your callback returns is what is actually output. So you could add a filter to “the_excerpt” that ignores the passed value and auto generates the excerpt from $post->post_content using wp_trim_excerpt() or wp_trim_words().

    The related code to declare callbacks and add filters can go in functions.php of a custom theme, functions.php of a child theme whose parent is a published theme, or a custom site specific plugin. In fact, all customizations besides altered theme templates should be done through filter and action callbacks. On occasions where required, pluggable functions can be declared in the same places. While you could use all of the above code locations on one site, you should pick one and manage it all through that one location.

    You have lots of viable options. Because calls to the_content() and the_excerpt() can appear on several different templates, I personally would use the filter approach, declaring the callbacks and adding the filters on functions.php of the custom theme. One callback added to two filters can cover all possible situations on all of the templates in a single code location.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to always display Automatic Excerpts?’ is closed to new replies.