Using WordPress ‘export_wp_filename’ PHP filter

The export_wp_filename WordPress PHP filter allows you to modify the default export filename for WordPress exports.

Usage

add_filter('export_wp_filename', 'my_custom_export_filename', 10, 3);
function my_custom_export_filename($wp_filename, $sitename, $date) {
    // your custom code here
    return $wp_filename;
}

Parameters

  • $wp_filename (string) – The original filename for the exported file.
  • $sitename (string) – The name of the site being exported.
  • $date (string) – Today’s date, formatted.

More information

See WordPress Developer Resources: export_wp_filename

Examples

Append Custom Text to Filename

Add a custom text “_customtext” to the export filename.

add_filter('export_wp_filename', 'append_custom_text_to_export_filename', 10, 3);
function append_custom_text_to_export_filename($wp_filename, $sitename, $date) {
    $wp_filename = $wp_filename . '_customtext';
    return $wp_filename;
}
// Output: "yourwebsite.wordpress.YYYY-MM-DD_customtext.xml"

Add Current Time to Filename

Add the current time to the export filename.

add_filter('export_wp_filename', 'add_current_time_to_export_filename', 10, 3);
function add_current_time_to_export_filename($wp_filename, $sitename, $date) {
    $time = date('H-i-s');
    $wp_filename = $sitename . '.wordpress.' . $date . '.' . $time . '.xml';
    return $wp_filename;
}
// Output: "yourwebsite.wordpress.YYYY-MM-DD.HH-MM-SS.xml"

Change File Extension

Change the export file extension from “.xml” to “.txt”.

add_filter('export_wp_filename', 'change_export_file_extension', 10, 3);
function change_export_file_extension($wp_filename, $sitename, $date) {
    $wp_filename = $sitename . '.wordpress.' . $date . '.txt';
    return $wp_filename;
}
// Output: "yourwebsite.wordpress.YYYY-MM-DD.txt"

Include Site Description in Filename

Add the site description to the export filename.

add_filter('export_wp_filename', 'include_site_description_in_export_filename', 10, 3);
function include_site_description_in_export_filename($wp_filename, $sitename, $date) {
    $site_description = get_bloginfo('description');
    $wp_filename = $sitename . '_' . $site_description . '.wordpress.' . $date . '.xml';
    return $wp_filename;
}
// Output: "yourwebsite_sitedescription.wordpress.YYYY-MM-DD.xml"

Prepend a Prefix to Filename

Prepend a custom prefix “backup-” to the export filename.

add_filter('export_wp_filename', 'prepend_prefix_to_export_filename', 10, 3);
function prepend_prefix_to_export_filename($wp_filename, $sitename, $date) {
    $wp_filename = 'backup-' . $wp_filename;
    return $wp_filename;
}
// Output: "backup-yourwebsite.wordpress.YYYY-MM-DD.xml"