render_block_core_home_link

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

WordPress Version: 6.5

/**
 * Renders the `core/home-link` block.
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The saved content.
 * @param WP_Block $block      The parsed block.
 *
 * @return string Returns the post content with the home url added.
 */
function render_block_core_home_link($attributes, $content, $block)
{
    if (empty($attributes['label'])) {
        // Using a fallback for the label attribute allows rendering the block even if no attributes have been set,
        // e.g. when using the block as a hooked block.
        // Note that the fallback value needs to be kept in sync with the one set in `edit.js` (upon first loading the block in the editor).
        $attributes['label'] = __('Home');
    }
    $aria_current = '';
    if (is_front_page()) {
        $aria_current = ' aria-current="page"';
    } elseif (is_home() && (int) get_option('page_for_posts') !== get_queried_object_id()) {
        // Edge case where the Reading settings has a posts page set but not a static homepage.
        $aria_current = ' aria-current="page"';
    }
    return sprintf('<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" rel="home"%3$s>%4$s</a></li>', block_core_home_link_build_li_wrapper_attributes($block->context), esc_url(home_url()), $aria_current, wp_kses_post($attributes['label']));
}

WordPress Version: 6.4

/**
 * Renders the `core/home-link` block.
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The saved content.
 * @param WP_Block $block      The parsed block.
 *
 * @return string Returns the post content with the home url added.
 */
function render_block_core_home_link($attributes, $content, $block)
{
    if (empty($attributes['label'])) {
        return '';
    }
    $aria_current = '';
    if (is_front_page()) {
        $aria_current = ' aria-current="page"';
    } elseif (is_home() && (int) get_option('page_for_posts') !== get_queried_object_id()) {
        // Edge case where the Reading settings has a posts page set but not a static homepage.
        $aria_current = ' aria-current="page"';
    }
    return sprintf('<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" rel="home"%3$s>%4$s</a></li>', block_core_home_link_build_li_wrapper_attributes($block->context), esc_url(home_url()), $aria_current, wp_kses_post($attributes['label']));
}

WordPress Version: 6.2

/**
 * Renders the `core/home-link` block.
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The saved content.
 * @param WP_Block $block      The parsed block.
 *
 * @return string Returns the post content with the home url added.
 */
function render_block_core_home_link($attributes, $content, $block)
{
    if (empty($attributes['label'])) {
        return '';
    }
    $aria_current = (is_home() || is_front_page() && 'page' === get_option('show_on_front')) ? ' aria-current="page"' : '';
    return sprintf('<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" rel="home"%3$s>%4$s</a></li>', block_core_home_link_build_li_wrapper_attributes($block->context), esc_url(home_url()), $aria_current, wp_kses_post($attributes['label']));
}

WordPress Version: 6.1

/**
 * Renders the `core/home-link` block.
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The saved content.
 * @param WP_Block $block      The parsed block.
 *
 * @return string Returns the post content with the home url added.
 */
function render_block_core_home_link($attributes, $content, $block)
{
    if (empty($attributes['label'])) {
        return '';
    }
    $aria_current = (is_home() || is_front_page() && 'page' === get_option('show_on_front')) ? ' aria-current="page"' : '';
    return sprintf('<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" "rel="home"%3$s>%4$s</a></li>', block_core_home_link_build_li_wrapper_attributes($block->context), esc_url(home_url()), $aria_current, wp_kses_post($attributes['label']));
}