Skip to content

Commit 2bc0044

Browse files
committed
Users: A11y: Improve title attributes in author link functions.
Remove the title attribute from `the_author_posts_link()` and related functions, retaining text for use in `the_author_posts_link` filter, and add parameter to disable title attributes in `the_author_link()`. Default behavior will still differentiate the two links, but adds the option to remove all title attributes. Props sabernhardt, alh0319, adnanlimdi, audrasjb, joedolson. Fixes #62835. See #26559. Built from https://develop.svn.wordpress.org/trunk@61745 git-svn-id: http://core.svn.wordpress.org/trunk@61051 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent aae345c commit 2bc0044

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

wp-includes/author-template.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,29 @@ function the_author_meta( $field = '', $user_id = false ) {
229229
* the author's name.
230230
*
231231
* @since 3.0.0
232+
* @since 7.0.0 Added `$use_title_attr` parameter.
232233
*
233234
* @global WP_User $authordata The current author's data.
234235
*
236+
* @param bool $use_title_attr Optional. Whether to add a title attribute.
237+
* Default true.
235238
* @return string An HTML link if the author's URL exists in user meta,
236239
* otherwise the result of get_the_author().
237240
*/
238-
function get_the_author_link() {
241+
function get_the_author_link( $use_title_attr = true ) {
239242
if ( get_the_author_meta( 'url' ) ) {
240243
global $authordata;
241244

242245
$author_url = get_the_author_meta( 'url' );
243246
$author_display_name = get_the_author();
244247

248+
/* translators: %s: Author's display name. */
249+
$author_title = sprintf( __( 'Visit %s’s website' ), $author_display_name );
250+
245251
$link = sprintf(
246-
'<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
252+
'<a href="%1$s"%2$s rel="author external">%3$s</a>',
247253
esc_url( $author_url ),
248-
/* translators: %s: Author's display name. */
249-
esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), $author_display_name ) ),
254+
$use_title_attr ? ' title="' . esc_attr( $author_title ) . '"' : '',
250255
$author_display_name
251256
);
252257

@@ -274,9 +279,13 @@ function get_the_author_link() {
274279
* @link https://developer.wordpress.org/reference/functions/the_author_link/
275280
*
276281
* @since 2.1.0
282+
* @since 7.0.0 Added `$use_title_attr` parameter.
283+
*
284+
* @param bool $use_title_attr Optional. Whether to add a title attribute.
285+
* Default true.
277286
*/
278-
function the_author_link() {
279-
echo get_the_author_link();
287+
function the_author_link( $use_title_attr = true ) {
288+
echo get_the_author_link( $use_title_attr );
280289
}
281290

282291
/**
@@ -310,6 +319,7 @@ function the_author_posts() {
310319
* Returns an HTML-formatted link using get_author_posts_url().
311320
*
312321
* @since 4.4.0
322+
* @since 7.0.0 Removed title attribute.
313323
*
314324
* @global WP_User $authordata The current author's data.
315325
*
@@ -322,22 +332,27 @@ function get_the_author_posts_link() {
322332
return '';
323333
}
324334

335+
$author = get_the_author();
336+
/* translators: %s: Author's display name. */
337+
$title = sprintf( __( 'Posts by %s' ), $author );
338+
325339
$link = sprintf(
326-
'<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
340+
'<a href="%1$s" rel="author">%2$s</a>',
327341
esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
328-
/* translators: %s: Author's display name. */
329-
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
330-
get_the_author()
342+
$author
331343
);
332344

333345
/**
334346
* Filters the link to the author page of the author of the current post.
335347
*
336348
* @since 2.9.0
349+
* @since 7.0.0 Added `$author` and `$title` parameters.
337350
*
338-
* @param string $link HTML link.
351+
* @param string $link HTML link.
352+
* @param string $author Author's display name.
353+
* @param string $title Text originally used for a title attribute.
339354
*/
340-
return apply_filters( 'the_author_posts_link', $link );
355+
return apply_filters( 'the_author_posts_link', $link, $author, $title );
341356
}
342357

343358
/**
@@ -536,10 +551,8 @@ function wp_list_authors( $args = '' ) {
536551
}
537552

538553
$link = sprintf(
539-
'<a href="%1$s" title="%2$s">%3$s</a>',
554+
'<a href="%1$s">%2$s</a>',
540555
esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ),
541-
/* translators: %s: Author's display name. */
542-
esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),
543556
$name
544557
);
545558

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-beta1-61744';
19+
$wp_version = '7.0-beta1-61745';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)