【问题标题】:WordPress hook for changing excerpt content when excerpt not set未设置摘录时用于更改摘录内容的 WordPress 钩子
【发布时间】:2020-06-14 08:53:35
【问题描述】:

标题几乎说明了一切。我需要一个过滤器来更改那些没有设置摘录的帖子的摘录内容。

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

也就是说,我需要连接一个可以访问自动生成的 except 的过滤器,然后让我更改它。

【问题讨论】:

    标签: wordpress wordpress-hook


    【解决方案1】:

    可能是这样的(未经测试)?

    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' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      • 2017-02-26
      • 2014-07-31
      相关资源
      最近更新 更多