Add custom attribute to gravity form fields


Gravity form wordpress plugin providing number of useful hooks to easily customize the form. I recently created gravity form add-on wordpress plugin. There I had situation to add custom attribute to the form field. I feel it’s useful share here, so it will be useful for someone.

Gravity form action hook gform_field_content is pretty useful to do our job. Let’s see how to do that!

add_filter( 'gform_field_content', 'add_custom_attr', 10);

function add_custom_attr($field_content, $field, $value, $lead_id, $form_id){

if($field->type == 'xxx'){

	$field_content = str_replace( 'type=', "data-custom_attr='yyyy' type=", $field_content );

return $content;


Posted in Cocktail, Wordpress and tagged by .

About Gowri

I am professional web developer with 8+ years experience. PHP, jQuery, WordPress, Angular and Ionic are my key skills in web development. I am working with strong enthusiastic team with spirit. We provide all web related solution like HTML/CSS development, Web graphic design and Logo.