How to Customize Available Date Ranges for the WPForms Dashboard Widget

Overview

Would you like to see more in your WPForms dashboard widget beside the default 7 or 30 days? You can easily add other increments to your dashboard widget. This tutorial will show you how to add an additional time span to pull your entry results.

The WPForms dashboard widget by default will only show you the last 7 and 30 day time spans

Setup

In this tutorial, we’ll show you how to change the time range displayed in the WPForms dashboard widget.

1) Adding the PHP Code

First you’ll need to add the following code to your site.

/**
 * Adding 90 day range to the dashboard widget time span.
 *
 * @link https://wpforms.com/developers/how-to-add-an-additional-time-span-to-the-dashboard-widget/
 *
function wpf_dev_dash_widget_timespan_options( $options ) {
    $options[] = 90;
    return $options;
}
add_filter( 'wpforms_dash_widget_timespan_options', 'wpf_dev_dash_widget_timespan_options' );

2) Viewing the changes

Click Dashboard from the WordPress admin menu on the left and now you’ll see you have a new option in the dropdown of 90 days in the Total Entries by Form dropdown.

With this code you'll add an additional time span of 90 days to the dashboard widget.

And that’s it! You’ve now successfully increased your dashboard widget time span to include a new 90 days range. If you’re not already familiar with the Entries screen, we recommend you take a look at this article for a complete guide to WPForms entries..

FAQ

Q: Can I add more ranges?

A: Absolutely! Here’s an example of including a 60 day range as well as the 90 day range.

/**
 * Adding 60 and 90 day range to the dashboard widget time span.
 *
 * @link https://wpforms.com/developers/how-to-add-an-additional-time-span-to-the-dashboard-widget/
 *
function wpf_dev_dash_widget_timespan_options( $options ) {
    $options[] = 60;
    $options[] = 90;
    return $options;
}
add_filter( 'wpforms_dash_widget_timespan_options', 'wpf_dev_dash_widget_timespan_options' );

Q: Will this also change the Entries screen?

A: No, this filter will only change the dashboard widget on the main WordPress Dashboard screen.

Q: Why doesn’t this include today’s date?

A: By default, the current day is excluded from the dashboard but you can easily include all current-day reporting with this separate code snippet.

/**
 * Include current-day reporting to the dashboard widget time span.
 *
 * @link https://wpforms.com/developers/how-to-add-an-additional-time-span-to-the-dashboard-widget/
 *
add_filter(
    'wpforms_dash_widget_date_end_str',
    function( $day ) {
        return 'today';
    }
);