Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
excerpt_more - 过滤在摘录后面显示的“更多”链接中的字符串 - WordPress钩子 - WordPress动力
当前浏览:首页 / WordPress钩子 / excerpt_more

apply_filters( 'excerpt_more', string $more_string )

过滤在摘录后面显示的“更多”链接中的字符串


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "7daa69091da2c3c5a00b72a3f5f57880" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "68c67200361cd28ac8de51b353489d43" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

excerpt 摘要more...


参数

$more_string

(string) “更多”链接中显示的字符串。


更多信息

该过滤器由wp_trim_excerpt()函数调用。默认情况下,过滤器设置为将“[…]”作为摘录末尾的摘录更多字符串进行回显。



源码

查看源码 官方文档


更新日志

版本描述
2.9.0开始引入

使用示例

  • 示例1

    如何将[…]替换为其他字符串?
    在下面的代码中,我们将[…]替换为 …
    您可以发送任何字符串作为返回值。

    /**
     * Change the excerpt more string
     */
     function my_theme_excerpt_more( $more ) {
         return '…';
     }
     add_filter( 'excerpt_more', 'my_theme_excerpt_more' );
    
  • 示例2

    如何在摘要中添加“继续阅读”链接

    function wpdocs_excerpt_more( $more ) {
        return sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
              esc_url( get_permalink( get_the_ID() ) ),
              sprintf( __( 'Continue reading %s', 'wpdocs' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
        );
    }
    add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );
  • 示例3

    从Codex迁移的示例:

    要更改摘录更多字符串,请将以下代码添加到主题中的functions.php文件中:

    function custom_excerpt_more( $more ) {
    	return '[.....]';
    }
    add_filter( 'excerpt_more', 'custom_excerpt_more' );
    

    对于早于2.9的版本,请使用:

    function custom_excerpt_more( $excerpt ) {
    	return str_replace( '[…]', '...', $excerpt );
    }
    add_filter( 'wp_trim_excerpt', 'custom_excerpt_more' );