Embeds: Include post name in "Continue reading" links to provide a readable link for screenreaders.

Props swissspidy.
Fixes #34481.

git-svn-id: https://develop.svn.wordpress.org/trunk@35432 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2015-10-29 13:20:04 +00:00
parent 78a2cf3db6
commit 391b67356a
2 changed files with 14 additions and 12 deletions

View File

@ -746,26 +746,27 @@ function wp_filter_oembed_result( $result, $data, $url ) {
}
/**
* Filters the string in the "more" link displayed after a trimmed excerpt.
* Filters the string in the 'more' link displayed after a trimmed excerpt.
*
* Replaces '[...]' (appended to automatically generated excerpts) with an
* ellipsis and a "Continue reading" link in the embed template.
*
* @since 4.4.0
*
* @param string $more_string The string shown within the more link.
* @return string The modified excerpt.
* @param string $more_string Default 'more' string.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function wp_embed_excerpt_more( $more_string ) {
if ( ! is_embed() ) {
return $more_string;
}
return sprintf(
_x( '… %s', 'read more link' ),
sprintf(
'<a class="wp-embed-more" href="%s" target="_top">%s</a>',
get_the_permalink(),
__( 'Read more' )
)
$link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
esc_url( get_permalink() ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' )
);
return ' &hellip; ' . $link;
}
/**

View File

@ -194,7 +194,8 @@ class Tests_Embed_Template extends WP_UnitTestCase {
function test_wp_embed_excerpt_more() {
$post_id = self::factory()->post->create( array(
'post_content' => 'Foo Bar',
'post_title' => 'Foo Bar',
'post_content' => 'Bar Baz',
) );
$this->assertEquals( '', wp_embed_excerpt_more( '' ) );
@ -204,7 +205,7 @@ class Tests_Embed_Template extends WP_UnitTestCase {
$actual = wp_embed_excerpt_more( '' );
$expected = sprintf(
'&hellip; <a class="wp-embed-more" href="%s" target="_top">Read more</a>',
' &hellip; <a href="%s" class="wp-embed-more" target="_top">Continue reading <span class="screen-reader-text">Foo Bar</span></a>',
get_the_permalink()
);