get_the_title

The timeline below displays how wordpress function get_the_title has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves the post title.
 *
 * 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.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $post_title = isset($post->post_title) ? $post->post_title : '';
    $post_id = isset($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);
}

WordPress Version: 5.5

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($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);
            $title = sprintf($protected_title_format, $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);
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filters the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 5.3

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($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);
            $title = sprintf($protected_title_format, $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);
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filters the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 4.6

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($post->ID) ? $post->ID : 0;
    if (!is_admin()) {
        if (!empty($post->post_password)) {
            /**
             * 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', __('Protected: %s'), $post);
            $title = sprintf($protected_title_format, $title);
        } elseif (isset($post->post_status) && 'private' == $post->post_status) {
            /**
             * 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', __('Private: %s'), $post);
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filters the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 4.2

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($post->ID) ? $post->ID : 0;
    if (!is_admin()) {
        if (!empty($post->post_password)) {
            /**
             * Filter 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', __('Protected: %s'), $post);
            $title = sprintf($protected_title_format, $title);
        } elseif (isset($post->post_status) && 'private' == $post->post_status) {
            /**
             * Filter 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', __('Private: %s'), $post);
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filter the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 4.0

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($post->ID) ? $post->ID : 0;
    if (!is_admin()) {
        if (!empty($post->post_password)) {
            /**
             * Filter 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', __('Protected: %s'), $post);
            $title = sprintf($protected_title_format, $title);
        } else if (isset($post->post_status) && 'private' == $post->post_status) {
            /**
             * Filter 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', __('Private: %s'), $post);
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filter the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 3.9

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($post->ID) ? $post->ID : 0;
    if (!is_admin()) {
        if (!empty($post->post_password)) {
            /**
             * Filter 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'.
             */
            $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
            $title = sprintf($protected_title_format, $title);
        } else if (isset($post->post_status) && 'private' == $post->post_status) {
            /**
             * Filter 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'.
             */
            $private_title_format = apply_filters('private_title_format', __('Private: %s'));
            $title = sprintf($private_title_format, $title);
        }
    }
    /**
     * Filter the post title.
     *
     * @since 0.71
     *
     * @param string $title The post title.
     * @param int    $id    The post ID.
     */
    return apply_filters('the_title', $title, $id);
}

WordPress Version: 3.7

/**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int|object $post Optional. Post ID or object.
 * @return string
 */
function get_the_title($post = 0)
{
    $post = get_post($post);
    $title = isset($post->post_title) ? $post->post_title : '';
    $id = isset($post->ID) ? $post->ID : 0;
    if (!is_admin()) {
        if (!empty($post->post_password)) {
            $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
            $title = sprintf($protected_title_format, $title);
        } else if (isset($post->post_status) && 'private' == $post->post_status) {
            $private_title_format = apply_filters('private_title_format', __('Private: %s'));
            $title = sprintf($private_title_format, $title);
        }
    }
    return apply_filters('the_title', $title, $id);
}