Description
The gform_form_theme_slug
filter can be used to filter the form theme.
Usage
Applies to all forms:
add_filter( 'gform_form_theme_slug', 'your_function_name', 10, 2 );
Parameters
- $slug string
The current theme slug for the form. - $form Form Object
The form object being processed.
Examples
1. Force theme when form embedded in specific post type
This example shows how you can set a specific theme to be always used when a form is embedded in a specific post type.
add_filter( 'gform_form_theme_slug', function( $slug, $form ) {
if ( get_post_type() !== 'regional_group' ) {
return $slug;
}
return 'gravity-theme';
}, 10, 2 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms 2.7
Source Code
This filter is located in class GFFormDisplay
in /form_display.php.