is_author()
Checks if the author's posts page is displayed. You can specify a specific author. Conditional tag.
Keep in mind that in conjunction with checks using the tag is_archive(), this tag should be used first, because is_archive() includes a check for is_author(). That is, if you first use is_archive() and then is_author() in the same logical structure, is_author() will never be executed.
No Hooks.
Returns
true|false.
Usage
if( is_author() ){
// ...
}
- $author(string)
- ID or nickname of the author whose page display needs to be checked. By default, it checks whether the author's page is displayed at all or if it is a completely different archive page.
Examples
#1 Various examples of how to use the function:
// When any author's page is displayed
is_author();
// When the page of an author whose ID is 4 is displayed
is_author('4');
// When the page of the author with the nickname "Vivian" is displayed
is_author('Vivian');
// Nickname can also be with a dash.
is_author('john-jones');
// You can specify more than one author, with mixing ID and Nickname.
is_author( [ 4, 'john-jones', 'Vivian' ] );
Notes
- Global. WP_Query.
$wp_queryWordPress Query object.
Changelog
| Since 1.5.0 | Introduced. |
is_author() is author code WP 7.0
function is_author( $author = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_author( $author );
}