• Rubidze

    (@rubidze)


    From other threads I see there is a way to get automatically created (first sentences of content) excerpts to be displayed via Pods template. I tried to add

    add_filter( 'the_excerpt', function(){
    ??? return wp_trim_excerpt();
    });

    to my child themes function.php and get the error that this can not be applied twice. Possibly this is already decleared by theme or some plugins. How to achieve this not braking things up?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Error Message

    Filters can be applied any number of times, but there is a common PHP error which refers to defining a function of the same name more than once. Check the error in error logs for the exact error and line number, or verify there is not a function of the same name defined twice.

    Filtering excerpt to be first sentence

    The below filters should provide the described behavior:

    <?php
    /**
    * Return first sentence as excerpt if a period followed by a space exists.
    *
    * https://developer.www.ads-software.com/reference/functions/get_the_excerpt/
    */
    add_filter(
    'get_the_excerpt',
    function( $excerpt, $id ) {
    if ( false !== strpos( $excerpt, '. ' ) ) {
    return sprintf(
    '%s&hellip;', // Text followed by ellipsis.
    explode( '. ', $excerpt )[0] // First sentence minus period.
    );
    }
    return $excerpt;
    },
    20,
    2
    );
    /**
    * Change the maximum length of the excerpt.
    */
    add_filter(
    'excerpt_length',
    function( $text, $post ) {
    return 100; // Maximum 100 words.
    },
    20,
    2
    );
    /**
    * Remove additional text after excerpt.
    */
    add_filter(
    'excerpt_more',
    function( $after_excerpt ) {
    return ''; // Nothing.
    },
    20,
    2
    );
    Thread Starter Rubidze

    (@rubidze)

    Indeed a function by this name already exist. Possibly by theme. or another plugin that gives an option to show posts list and show first 50 words if no excerpt exist.

    So, is there a way to use already automatically generated excerpt in pod template?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.