wp_maybe_decline_date()
Determines if the date should be declined.
If the locale specifies that month names require a genitive case in certain formats (like 'j F Y'), the month name will be replaced with a correct form.
No Hooks.
Return
String
. The date, declined if locale specifies it.
Usage
wp_maybe_decline_date( $date, $format );
- $date(string) (required)
- Formatted date string.
- $format(string)
- Date format to check.
Default: empty string
Examples
#1 Date conversion examples
This will work only if site language date parts can be declined. This option is set in translation string 'on' === _x( 'off', 'decline months names: on or off' )
.
For example, suppose our site is running in the Russian language, where months could be declined, then:
echo wp_maybe_decline_date( '15 Май 2019' ); //> 15 мая 2019
The date has the right format, but the month is already written in it correctly - the function does not change anything, although it does all the same operations to find a replacement.
echo wp_maybe_decline_date( '15 Мая 2019' ); //> 15 Мая 2019 echo wp_maybe_decline_date( '15 мая 2019' ); //> 15 мая 2019
The date has the wrong format, the function just returns it without any attempt to change anything.
echo wp_maybe_decline_date( 'Май 2019 года' ); //> Май 2019 года
Notes
- Global. WP_Locale. $wp_locale WordPress date and time locale object.
Changelog
Since 4.4.0 | Introduced. |
Since 5.4.0 | The $format parameter was added. |