Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DeveloperWil/5de4db2779428213d5ee to your computer and use it in GitHub Desktop.

Select an option

Save DeveloperWil/5de4db2779428213d5ee to your computer and use it in GitHub Desktop.
Place Gravity Forms complex labels above fields
/**
* register custom form scripts
* @param array $form
* @return array
*/
add_filter('gform_register_init_scripts', function($form) {
ob_start();
?>
jQuery(".ginput_container").has("input[type='email'],input[type='text'],input[type='password'],select,textarea").find("label").each(function() {
var e = jQuery(this), fielddesc = jQuery("<div>").append(e.clone()).remove().html();
e.siblings("input,select,textarea").before(fielddesc);
e.remove();
});
<?php
$script = ob_get_clean();
GFFormDisplay::add_init_script($form['id'], 'gravity-forms-fields-above', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment