get_day_link( int|false $year, int|false $month, int|false $day ): string

Retrieves the permalink for the day archives with year and month.


Parameters

$year int|false Required
Integer of year. False for current year.
$month int|false Required
Integer of month. False for current month.
$day int|false Required
Integer of day. False for current day.

Top ↑

Return

string The permalink for the specified day, month, and year archive.


Top ↑

Source

File: wp-includes/link-template.php. View all references

function get_day_link( $year, $month, $day ) {
	global $wp_rewrite;
	if ( ! $year ) {
		$year = current_time( 'Y' );
	}
	if ( ! $month ) {
		$month = current_time( 'm' );
	}
	if ( ! $day ) {
		$day = current_time( 'j' );
	}

	$daylink = $wp_rewrite->get_day_permastruct();
	if ( ! empty( $daylink ) ) {
		$daylink = str_replace( '%year%', $year, $daylink );
		$daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink );
		$daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink );
		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
	} else {
		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
	}

	/**
	 * Filters the day archive permalink.
	 *
	 * @since 1.5.0
	 *
	 * @param string $daylink Permalink for the day archive.
	 * @param int    $year    Year for the archive.
	 * @param int    $month   Month for the archive.
	 * @param int    $day     The day for the archive.
	 */
	return apply_filters( 'day_link', $daylink, $year, $month, $day );
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Use With Variables

    PHP code block for use within The Loop: Assigns year, month and day of a post to the variables $arc_year, $arc_month and $arc_day. These are used with the get_day_link() tag, which returns the URL as a link to the daily archive for that post, displaying it within an anchor tag with the PHP echo command. See Formatting Date and Time for info on format strings used in get_the_time() tag.

    <?php 
    $archive_year  = get_the_time( 'Y' ); 
    $archive_month = get_the_time( 'm' ); 
    $archive_day   = get_the_time( 'd' ); 
    ?>
    <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>">
    	<?php _e( 'This day’s posts', 'textdomain' ); ?>
    </a>

You must log in before being able to contribute a note or feedback.