0

How can I modify the get_the_excerpt() when the post-format of the post is set to quote?

1 Answer 1

1

While writing the question in SE I already found the solution:

add_filter( 'get_the_excerpt', 'get_custom_the_excerpt' );

function get_custom_the_excerpt($excerpt) {

    $post = get_post();
    $format = get_post_format( $post );

    // modify excerpt if it is a quote, for example set title as author 
    if ($format == 'quote') {
        $output = '<q>'. $excerpt. '</q>
                <p class="quoted">'.get_the_title().'</p>';
    } 

    // return excerpt without change
    else {
        $output = $excerpt;
    }

    return $output;

}

For details check get_the_excerpt() and get_post_format().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.