Using WordPress ‘get_feed_build_date’ PHP filter

The get_feed_build_date WordPress PHP filter retrieves the date the last post or comment in the query was modified.

Usage

add_filter('get_feed_build_date', 'your_custom_function', 10, 2);

function your_custom_function($max_modified_time, $format) {
    // your custom code here
    return $max_modified_time;
}

Parameters

  • $max_modified_time (string|false) – Date the last post or comment was modified in the query, in UTC. False on failure.
  • $format (string) – The date format requested in get_feed_build_date().

More information

See WordPress Developer Resources: get_feed_build_date

Examples

Change the date format

To change the date format for the feed build date:

add_filter('get_feed_build_date', 'change_feed_build_date_format', 10, 2);

function change_feed_build_date_format($max_modified_time, $format) {
    return date('F j, Y', strtotime($max_modified_time));
}

Add a prefix to the date

To add a prefix to the feed build date:

add_filter('get_feed_build_date', 'add_prefix_to_feed_build_date', 10, 2);

function add_prefix_to_feed_build_date($max_modified_time, $format) {
    return 'Last Modified: ' . $max_modified_time;
}

Convert the date to local time

To convert the feed build date to local time:

add_filter('get_feed_build_date', 'convert_feed_build_date_to_local', 10, 2);

function convert_feed_build_date_to_local($max_modified_time, $format) {
    $date = new DateTime($max_modified_time);
    $date->setTimeZone(new DateTimeZone('America/New_York'));
    return $date->format($format);
}

Use a custom date format

To use a custom date format for the feed build date:

add_filter('get_feed_build_date', 'custom_feed_build_date_format', 10, 2);

function custom_feed_build_date_format($max_modified_time, $format) {
    return date('l, F jS, Y', strtotime($max_modified_time));
}

Display the time ago

To display the time ago since the feed was last built:

add_filter('get_feed_build_date', 'display_feed_build_date_time_ago', 10, 2);

function display_feed_build_date_time_ago($max_modified_time, $format) {
    $time_ago = human_time_diff(strtotime($max_modified_time));
    return sprintf('%s ago', $time_ago);
}