WordPress 7.0 removes—or facilitates removing—title attributes from links relating to post authors.
Author’s Website link (from the user profile)
get_the_author_link() and the_author_link() have a new $use_title_attr parameter, which can be set to false to remove the “Visit Author’s website” tooltip. By default, these functions continue to include a title attribute.
<?php
// either
the_author_link();
// or
echo get_the_author_link();
Default output is the same in 7.0 as in 6.9:
<a href="https://author.example.com" title="Visit Author’s website" rel="author external">Author</a>
<?php
// either
the_author_link( false );
// or
echo get_the_author_link( false );
Output in 7.0:
<a href="https://author.example.com" rel="author external">Author</a>
Author’s posts archive link
The “Posts by Author” title attribute is removed from the link by default. However, the title text is still available for use within the the_author_posts_link hook, along with the author’s display name.
<?php
// either
the_author_posts_link();
// or
echo get_the_author_posts_link();
Output in 6.9:
<a href="https://example.org/author/author/" title="Posts by Author" rel="author">Author</a>
Output in 7.0:
<a href="https://example.org/author/author/" rel="author">Author</a>
Editing the posts link text
To replace the author name with the “Posts by Author” text, use multiple arguments in the the_author_posts_link filter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output..
<?php
/**
* Edits text for the link to the author page of the author of the current post.
*
* Add "Posts by" before the author's display name (or after the name in some translations):
* `<a href="https://example.org/author/author/" rel="author">Posts by Author</a>`
*
* @param string $link HTML link.
* @param string $author Author's display name. Default empty string.
* @param string $title Text originally used for a title attribute. Default empty string.
*/
function wpdocs_author_posts_link( $link, $author = '', $title = '' ) {
// In WordPress versions prior to 7.0, $author and $title would be empty.
if ( '' !== $title && '' !== $author ) {
$link = str_replace(
'>' . $author . '</a>',
'>' . esc_html( $title ) . '</a>',
$link
);
}
return $link;
}
add_filter( 'the_author_posts_link', 'wpdocs_author_posts_link', 10, 3 );
Authors list HTML HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers.
wp_list_authors() simply removes the “Posts by Author” tooltips.
<?php
wp_list_authors(
array(
'html' => true // This is true by default.
)
);
Output in 6.9:
<li><a href="https://example.org/author/author/" title="Posts by Author">Author</a></li><li><a href="https://example.org/author/editor/" title="Posts by Editor">Editor</a></li>
Output in 7.0:
<li><a href="https://example.org/author/author/">Author</a></li><li><a href="https://example.org/author/editor/">Editor</a></li>
For more information, refer to #62835.
Props to @amykamala and @audrasjb for review.
#7-0, #dev-notes, #dev-notes-7-0