September 16, 2013

Using get_template_part to display a WordPress template/loop inside a Gravity Forms field

Want to load a template part from your theme inside a Gravity Forms field? Here’s what you need to do.

Open up functions.php and add the following to it

function my_custom_template() {
    get_template_part( 'loop' );
    return ob_get_clean();

Make sure to point to the right template part.

Now add the following snippet right below that:

add_filter("gform_field_input", "gform_template_part", 10, 5);
function gform_template_part($input, $field, $value, $lead_id, $form_id){
    if($field["cssClass"] == "template_part"){

        $input = my_custom_template();
    return $input;

Now go to your Gravity Form and add a new HTML field. Go to advanced and put in the following CSS Class name:


Save your form and the template part should now be loaded and displaying!


Would you like to share your thoughts?

Would you like to share your thoughts?

Leave a Reply