函数文档

wp_embed_excerpt_more()

💡 云策文档标注

概述

wp_embed_excerpt_more() 是一个 WordPress 过滤器函数,用于修改在嵌入模板中显示的摘要后的“更多”链接字符串。它自动将摘要末尾的‘[…]’替换为省略号和“继续阅读”链接。

关键要点

  • 此函数仅在 is_embed() 返回 true 时生效,否则返回原始 $more_string。
  • 它生成一个包含文章标题的“继续阅读”链接,并前置省略号。
  • 函数返回一个字符串,格式为“ … Continue reading 文章标题”。

代码示例

function wp_embed_excerpt_more( $more_string ) {
	if ( ! is_embed() ) {
		return $more_string;
	}

	$link = sprintf(
		'<a href="%1$s" class="wp-embed-more">%2$s</a>',
		esc_url( get_permalink() ),
		/* translators: %s: Post title. */
		sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' )
	);
	return ' … ' . $link;
}

注意事项

  • 此函数从 WordPress 4.4.0 版本开始引入。
  • 它依赖于多个相关函数,如 is_embed()、get_the_title()、__()、esc_url() 和 get_permalink()。
  • 开发者可以通过此过滤器自定义嵌入模板中的“更多”链接文本和格式。

📄 原文内容

Filters the string in the ‘more’ link displayed after a trimmed excerpt.

Description

Replaces ‘[…]’ (appended to automatically generated excerpts) with an ellipsis and a “Continue reading” link in the embed template.

Parameters

$more_stringstringrequired
Default 'more' string.

Return

string ‘Continue reading’ link prepended with an ellipsis.

Source

function wp_embed_excerpt_more( $more_string ) {
	if ( ! is_embed() ) {
		return $more_string;
	}

	$link = sprintf(
		'<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
		esc_url( get_permalink() ),
		/* translators: %s: Post title. */
		sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' )
	);
	return ' … ' . $link;
}

Changelog

Version Description
4.4.0 Introduced.