WordPress at a glance

the_author() WP 0.71

Display the name of the author of the current post.

Must be used inside WordPress Loop.

The behavior of this function is based on old functionality predating get_the_author(). This function is not deprecated but is designed to echo the value from get_the_author() and as a result of any old theme that might still use the old behavior will also pass the value from get_the_author().

The normal, expected behavior of this function is to echo the author and not return it. If you need return the value to use further in php use get_the_author().

Works based on: get_the_author()
✈ 1 time = 0.000044s = very fast | 50000 times = 0.49s = very fast PHP 7.1.2, WP 4.7.3

No Hooks.

Return

null/string. Display author name.

Usage

<?php the_author(); ?>

Old usage:

<?php the_author( $deprecated, $deprecated_echo ); ?>
$deprecated(string)
Deprecated.
Default: ''
$deprecated_echo(string)
Deprecated. Use get_the_author(). Echo the string or return it.
Default: true

Examples

#1 Output the public name of the author of the post in the WordPress cycle

The public name is specified in the setting: "display as"

<p>The author of the post: <?php the_author(); ?></p>

#2 Get the author's name using the get_the_author() function:

$author = get_the_author();
echo "The author of the post: ". $author;

Code of the_author: wp-includes/author-template.php VER 4.9.8

<?php
function the_author( $deprecated = '', $deprecated_echo = true ) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '2.1.0' );
	}

	if ( true !== $deprecated_echo ) {
		_deprecated_argument( __FUNCTION__, '1.5.0',
			/* translators: %s: get_the_author() */
			sprintf( __( 'Use %s instead if you do not want the value echoed.' ),
				'<code>get_the_author()</code>'
			)
		);
	}

	if ( $deprecated_echo ) {
		echo get_the_author();
	}

	return get_the_author();
}

Related Functions

From tag: WP Loop

More from category: Posts, pages...

More from Template Tags: Authors

No comments
    Hello, !     Log In . Register