In WordPress, calendar_week_mod() is a small helper used by get_calendar(). It takes a number and wraps it into the range 0 to 6, like a "mod 7" for the days of the week.
It also works for negative numbers, which is why it is used to find how many empty cells come before the first day of the month.
Syntax
Pass one whole number. You get a number from 0 to 6 back.
WordPress
<?php
$day = calendar_week_mod( 8 );
echo $day;
Call
What it does
calendar_week_mod( 8 )
Returns 1 (8 is one day after a full week).
calendar_week_mod( 14 )
Returns 0 (two full weeks).
calendar_week_mod( -1 )
Returns 6 (one step back from 0).
For normal use, call get_calendar(). This helper is for custom calendar code.
Full declaration
WordPress
calendar_week_mod( int $num ): int
Parameters
Parameter
Description
$num
int. The number to wrap into the 0 to 6 range.
Return Value
Return Value
Description
int
The remainder after dividing by 7, always from 0 to 6.
WordPress Examples
Three short theme examples. Each one shows the code and what it prints.