get_the_author() – возвращает display_name автора текущего поста

Функция get_the_author() не имеет параметров и должна использоваться непосредственно в цикле WordPress. Смотрите мой видеоурок про циклы.

get_the_author( $deprecated = '' )

Возвращает display_name (имя в опции «Отображать как») автора текущего поста в цикле.

display name пользователя WordPress

Для получения ID пользователя поста или каких-то других его данных, рекомендую воспользоваться функцией get_the_author_meta().

Пример

$author = get_the_author();
echo 'Автор материала: ' . $author;

Фильтр the_author

При помощи фильтр-хука the_author вы можете изменить значение возвращаемого имени пользователя, например, я не хочу, чтобы было палевно, что пользователь имеет логин admin, тогда я могу применить такую функцию к хуку:

add_filter( 'the_author', 'true_change_admin' );
 
function true_change_admin( $display_name ) {
 
	if( 'admin' == $display_name ) {
		$display_name = 'stranger351';
	}
	return $display_name;
 
}

Не знаете, куда вставлять код?

Кодекс WordPress: Пользователи, Цикл: add_user_meta(), author_can(), wp_login_form(), current_user_can(), email_exists(), get_avatar(), get_avatar_url(), get_children(), get_current_user_id(), get_delete_post_link(), get_edit_post_link(), get_extended(), get_next_posts_link(), get_permalink(), get_post_type(), get_posts(), get_previous_posts_link(), get_queried_object_id(), get_query_var(), get_search_query(), get_the_author(), get_the_author_meta(), get_the_author_posts(), get_the_content(), get_the_date(), get_the_excerpt(), get_the_ID(), get_the_modified_author(), get_the_time(), get_the_title(), get_user_by(), get_user_meta(), has_excerpt(), has_post_thumbnail(), have_posts(), is_user_logged_in(), next_posts_link(), paginate_links(), post_class(), previous_posts_link(), query_posts(), setup_postdata(), the_author(), the_content(), the_date(), the_excerpt(), the_ID(), the_permalink(), the_post(), the_search_query(), the_time(), the_title(), the_title_attribute(), update_user_meta(), username_exists(), wp(), wp_dropdown_users(), wp_get_current_user(), wp_insert_user(), wp_new_user_notification(), WP_Query, wp_reset_postdata(), wp_reset_query(), wp_set_auth_cookie(), wp_set_password(), wp_signon(), WP_User_Query

Источник: Блог Миши Рудрастых

Миша Рудрастых

Путешествует по миру и рассказывает всем о WordPress лично, у себя в блогах и на курсах в Санкт-Петербурге. Умеет просто объяснять сложные вещи, делает это красиво. Организовывает неплохие WordCamp's, но совсем не умеет слушать чужие доклады.

Добавить комментарий