How to Get Default Values from Shortcode Attributes in contact form 7 | Wordpress

Опубликовано: 15 Май 2019
на канале: Kamlesh Jangir
2,433
28

Sometimes you may feel that it would be useful if you could use values from [contact-form-7 ...] shortcode attributes.

In such cases, you can use the default:shortcode_attr form-tag option, which retrieves the field default value from shortcode attributes.

default:shortcode_attr


How get custom value in contact form 7 shortcode in wordpress


add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
$my_attr = 'role_title';

if ( isset( $atts[$my_attr] ) ) {
$out[$my_attr] = $atts[$my_attr];
}

return $out;
}