get_year_link

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

WordPress Version: 5.4

/**
 * Retrieves the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|false $year Integer of year. False for current year.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filters the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 5.3

/**
 * Retrieves the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filters the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 5.2

/**
 * Retrieves the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filters the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 4.6

/**
 * Retrieves the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filters the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 4.3

/**
 * Retrieve the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filter the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 4.1

/**
 * Retrieve the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string The permalink for the specified year archive.
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filter the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 3.9

/**
 * Retrieve the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        $yearlink = home_url(user_trailingslashit($yearlink, 'year'));
    } else {
        $yearlink = home_url('?m=' . $year);
    }
    /**
     * Filter the year archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $yearlink Permalink for the year archive.
     * @param int    $year     Year for the archive.
     */
    return apply_filters('year_link', $yearlink, $year);
}

WordPress Version: 3.7

/**
 * Retrieve the permalink for the year archives.
 *
 * @since 1.5.0
 *
 * @param int|bool $year False for current year or year for permalink.
 * @return string
 */
function get_year_link($year)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    $yearlink = $wp_rewrite->get_year_permastruct();
    if (!empty($yearlink)) {
        $yearlink = str_replace('%year%', $year, $yearlink);
        return apply_filters('year_link', home_url(user_trailingslashit($yearlink, 'year')), $year);
    } else {
        return apply_filters('year_link', home_url('?m=' . $year), $year);
    }
}