функция since 0.71

get_the_title()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

get_the_title( int|WP_Post $post ): string

Описание

Если запись защищена паролем, а посетитель не является администратором, перед заголовком записи будет вставлено «Protected». Если запись приватная, перед заголовком записи будет вставлено «Private».

Оригинал (английский)

If the post is protected and the visitor is not an admin, then “Protected” will be inserted before the post title. If the post is private, then “Private” will be inserted before the post title.

Параметры

$post int|WP_Post необязательный
ID записи или объект WP_Post. По умолчанию — глобальная переменная $post.

Возвращаемое значение

string

Исходный код

wp-includes/post-template.php:118

function get_the_title( $post = 0 ) {
	$post = get_post( $post );

	$post_title = $post->post_title ?? '';
	$post_id    = $post->ID ?? 0;

	if ( ! is_admin() ) {
		if ( ! empty( $post->post_password ) ) {

			/* translators: %s: Protected post title. */
			$prepend = __( 'Protected: %s' );

			/**
			 * Filters the text prepended to the post title for protected posts.
			 *
			 * The filter is only applied on the front end.
			 *
			 * @since 2.8.0
			 *
			 * @param string  $prepend Text displayed before the post title.
			 *                         Default 'Protected: %s'.
			 * @param WP_Post $post    Current post object.
			 */
			$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );

			$post_title = sprintf( $protected_title_format, $post_title );
		} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {

			/* translators: %s: Private post title. */
			$prepend = __( 'Private: %s' );

			/**
			 * Filters the text prepended to the post title of private posts.
			 *
			 * The filter is only applied on the front end.
			 *
			 * @since 2.8.0
			 *
			 * @param string  $prepend Text displayed before the post title.
			 *                         Default 'Private: %s'.
			 * @param WP_Post $post    Current post object.
			 */
			$private_title_format = apply_filters( 'private_title_format', $prepend, $post );

			$post_title = sprintf( $private_title_format, $post_title );
		}
	}

	/**
	 * Filters the post title.
	 *
	 * @since 0.71
	 *
	 * @param string $post_title The post title.
	 * @param int    $post_id    The post ID.
	 */
	return apply_filters( 'the_title', $post_title, $post_id );
}

История изменений

ВерсияОписание
0.71 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.