Skip to content

Instantly share code, notes, and snippets.

@davecurrierseo
Created November 7, 2017 21:46
Show Gist options
  • Save davecurrierseo/af3f84bb1de4f543dbfabd4a73a1be16 to your computer and use it in GitHub Desktop.
Save davecurrierseo/af3f84bb1de4f543dbfabd4a73a1be16 to your computer and use it in GitHub Desktop.
Add Form Name as a Data Attribute to Gravity Forms Form Element
/**
* Adds form title to a data attribute on the form element
* @param [string] $form_tag The string containing the <form> tag
* @param [object] $form The current form
* @return [string] The new <form> tag string
*/
function gravity_form_tag($form_tag, $form) {
$form_title = $form['title'];
$form_tag = str_replace('<form', "<form data-formtitle='{$form_title}'", $form_tag);
return $form_tag;
}
add_filter('gform_form_tag', 'gravity_form_tag', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment