Using Gravity Forms ‘gform_display_add_form_button’ PHP filter

The gform_display_add_form_button filter in Gravity Forms permits the “Add Form” button to be displayed in different pages or scenarios beyond the default Post or Page edit screens in the classic editor. Note that a TinyMCE input is required for the button to be displayed.

Usage

Here’s a generic example of how to use the filter:

add_filter( 'gform_display_add_form_button', 'display_form_button_on_custom_page' );

function display_form_button_on_custom_page($display_add_form_button) {
    // your custom code here
    return $display_add_form_button;
}

Parameters

  • $display_add_form_button (bool): Indicates if the Add Form button and shortcode UI should be included for the current admin page.

More information

See Gravity Forms Docs: gform_display_add_form_button
This function is available since Gravity Forms version 2.5.

Examples

Enable Based on Query String

The code below enables the “Add Form” button on a custom page whose URL contains a specific query string “page=my_page”.

add_filter( 'gform_display_add_form_button', 'display_form_button_on_custom_page' );

function display_form_button_on_custom_page($display_add_form_button) {
    if (isset($_GET['page']) && $_GET['page'] == 'my_page') {
        return true;
    }
    return $display_add_form_button;
}

Disable Everywhere

This simple code disables the “Add Form” button everywhere.

add_filter( 'gform_display_add_form_button', '__return_false' );

Enable Everywhere

This simple code enables the “Add Form” button everywhere.

add_filter( 'gform_display_add_form_button', '__return_true' );

Enable Based on WP_Screen Base

The following code enables the “Add Form” button if the page is not a post page.

add_filter( 'gform_display_add_form_button', function ($display_add_form_button) {
    global $current_screen;
    return $current_screen instanceof WP_Screen && $current_screen->base != 'post' ? true : $display_add_form_button;
});

Enable for Divi

This code enables the “Add Form” button for the page and post editor when the Divi theme is active.

add_filter( 'gform_display_add_form_button', function ($display_add_form_button) {
    if ($display_add_form_button || !class_exists('ET_Builder_Plugin_Compat_Gravityforms')) {
        return $display_add_form_button;
    }
    $enable_classic_editor = apply_filters('et_builder_enable_classic_editor', isset($_GET['et_classic_editor']));
    return $enable_classic_editor && in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'));
});