How to add a custom attribute?

前端 未结 4 2077
走了就别回头了
走了就别回头了 2021-02-04 07:53

How to add a custom attribute in the field Contact Form 7 without javascript ?

For example, there is such a field on the page:



        
4条回答
  •  渐次进展
    2021-02-04 08:34

    Multiple attributes can be added also. eg

    add_filter( 'wpcf7_form_elements', 'imp_wpcf7_form_elements' );
    
    function imp_wpcf7_form_elements( $content ) {
        $str_pos = strpos( $content, 'name="your-email-homepage"' );
        $content = substr_replace( $content, ' aria-describedby="emailHelp" ', $str_pos, 0 );
    
        $str_pos2 = strpos( $content, 'name="your-fname-homepage"' );
        $content = substr_replace( $content, ' aria-describedby="fnameHelp" ', $str_pos2, 0 );
    
        $str_pos3 = strpos( $content, 'name="your-lname-homepage"' );
        $content = substr_replace( $content, ' aria-describedby="lnameHelp" ', $str_pos3, 0 );
        return $content;        
    }
    

提交回复
热议问题