Last updated

This page used to be a guide teaching you how to embed a Gravity Form with PHP. Very recently, Gravity Forms (finally!) added the ability to ‘nicely’ echo the form with PHP, so the guide is no longer needed.
Just so you know how, to echo a Gravity Form with PHP, you can now simply use something like what I’ve included in my imaginary function return statement below:
return "<p>Just fill out the form below to get started: ".gravity_form(4, false, false, false, null, false, 1, false). "<p>Thanks</p>";
The key part is that the last parameter (which says whether or not to echo the returned form) is set to FALSE – And that’s it! No more need for hacks!
Thanks to Elvis for pointing this update out to me!
Gravity Forms function gravity_form() has an $echo last parameter where you basically can specify if you want to echo right away the form or just return the form content. This way you control the behavior of the function and you are able to use it inside functions.php as well.
Check the documentation and the description for each parameter. https://www.gravityhelp.com/documentation/article/embedding-a-form/#usage-examples
Thanks for the update!
Back in April (2015) this parameter didn’t exist:
https://web.archive.org/web/20150411082153/http://www.gravityhelp.com/documentation/gravity-forms/user-guides/getting-started/embedding-a-form/
But now, as you say, it apparently does! https://www.gravityhelp.com/documentation/article/embedding-a-form/
I’ve updated the post accordingly!
Cheers Elvis