get_month_link

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

WordPress Version: 5.6

/**
 * Retrieves the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|false $year  Integer of year. False for current year.
 * @param int|false $month Integer of month. False for current month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    if (!$month) {
        $month = current_time('m');
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise((int) $month, 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filters the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 5.4

/**
 * Retrieves the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|false $year  Integer of year. False for current year.
 * @param int|false $month Integer of month. False for current month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    if (!$month) {
        $month = current_time('m');
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filters the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 5.3

/**
 * Retrieves the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param bool|int $year  False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    if (!$month) {
        $month = current_time('m');
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filters the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 5.2

/**
 * Retrieves the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param bool|int $year  False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = current_time('Y');
    }
    if (!$month) {
        $month = current_time('m');
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filters the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 4.6

/**
 * Retrieves the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param bool|int $year  False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    if (!$month) {
        $month = gmdate('m', current_time('timestamp'));
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filters the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 4.3

/**
 * Retrieve the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param bool|int $year  False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    if (!$month) {
        $month = gmdate('m', current_time('timestamp'));
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filter the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 4.1

/**
 * Retrieve the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @param bool|int $year False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string The permalink for the specified month and year archive.
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    if (!$month) {
        $month = gmdate('m', current_time('timestamp'));
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filter the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 3.9

/**
 * Retrieve the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @param bool|int $year False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    if (!$month) {
        $month = gmdate('m', current_time('timestamp'));
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        $monthlink = home_url(user_trailingslashit($monthlink, 'month'));
    } else {
        $monthlink = home_url('?m=' . $year . zeroise($month, 2));
    }
    /**
     * Filter the month archive permalink.
     *
     * @since 1.5.0
     *
     * @param string $monthlink Permalink for the month archive.
     * @param int    $year      Year for the archive.
     * @param int    $month     The month for the archive.
     */
    return apply_filters('month_link', $monthlink, $year, $month);
}

WordPress Version: 3.7

/**
 * Retrieve the permalink for the month archives with year.
 *
 * @since 1.0.0
 *
 * @param bool|int $year False for current year. Integer of year.
 * @param bool|int $month False for current month. Integer of month.
 * @return string
 */
function get_month_link($year, $month)
{
    global $wp_rewrite;
    if (!$year) {
        $year = gmdate('Y', current_time('timestamp'));
    }
    if (!$month) {
        $month = gmdate('m', current_time('timestamp'));
    }
    $monthlink = $wp_rewrite->get_month_permastruct();
    if (!empty($monthlink)) {
        $monthlink = str_replace('%year%', $year, $monthlink);
        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
        return apply_filters('month_link', home_url(user_trailingslashit($monthlink, 'month')), $year, $month);
    } else {
        return apply_filters('month_link', home_url('?m=' . $year . zeroise($month, 2)), $year, $month);
    }
}