未设置摘录时用于更改摘录内容的 WordPress 钩子

WordPress hook for changing excerpt content when excerpt not set

标题几乎说明了所有内容。我需要一个过滤器,可以用来更改那些没有摘录集的帖子的摘录内容。

现在,我已经尝试了the_excerptget_the_excerpt,它们都传递了一个参数,并且在这两种情况下都说参数是空字符串。

就是说,我需要连接到一个可以访问 auto-generated except 的过滤器,让我更改它。

也许是这样的(未经测试)?

function my_filter_the_excerpt( $excerpt ) {

    global $post;

    if( empty( $post->post_excerpt ) ) {
        // Excerpt is auto-generated
        $excerpt = 'Something else...';
    }
    return $excerpt;

}
add_filter( 'get_the_excerpt', 'my_filter_the_excerpt' );