benecaster_format_duration()
benecaster_format_duration( string $duration ): string
Formats an episode duration the way Benecaster’s website shows it: hours and minutes, H:MM, rounded to the nearest minute. 00:47:23 becomes 0:47, 01:00:31 becomes 1:01 and 100:00:00 becomes 100:00, and a length above zero is never 0:00 (a 45-second trailer shows 0:01). 0:47 is forty-seven minutes.
Benecaster’s episode cards and the [benecaster_latest_episode] shortcode both call it. Use it in a theme override, or anywhere a template prints _benecaster_duration, so the figure matches theirs. The result passes through benecaster_duration_display, so a format the site has chosen reaches every caller.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
duration |
string |
— | Yes | A duration as stored or filtered: the stored HH:MM:SS, M:SS, H:MM:SS or bare seconds (2843). |
Return Value
Type:
string
The duration for display. '' for an empty duration. A value that is not a duration comes back trimmed but otherwise as given.
Example
// In a theme template, inside a loop over episodes.
$duration = function_exists( 'benecaster_format_duration' )
? benecaster_format_duration( (string) get_post_meta( get_the_ID(), '_benecaster_duration', true ) )
: '';
if ( '' !== $duration ) {
printf( '<span class="my-episode-duration">%s</span>', esc_html( $duration ) );
}
Hooks Fired
Notes
Display only. Nothing stored changes, and the feed, REST's duration and the episode editor keep HH:MM:SS.
Format first, then test the result, not the stored value: a benecaster_duration_display callback may return '' to hide the figure, and Benecaster's own card makes the same check. See Show an episode duration in a custom template.
Need this built rather than just documented? See our services →