説明
について wpforms_display_field_before
アクションは、フォームが表示される前に発生し、ラベルなどの特定のフォーム要素の位置を決定します。
パラメータ
- フィールド
- (配列) サニタイズされたエントリーフィールドの値/プロパティ。
- フォームデータ
- (配列) フォームの設定/データ。
ソース
wpforms/src/Frontend/Frontend.php
詳細情報
このアクションはフォームが表示される前に実行されます。このアクションは、フォームフィールドのラベルなど、フォームの属性を移動させるために使うことができます。
例
この例では、アクションを削除することでラベルを完全に削除する。
/** * Action fires before the form is displayed to determine the position of certain form elements such as labels. * * @link https://wpforms.com/developers/wpforms_display_field_before/ * * @param array $fields Sanitized entry field values/properties. * @param array $form_data Form settings/data. * @return array */ function wpf_dev_display_field_before( $field, $form_data ) { // Only run this snippet on the form with the ID of 879 if ( absint( $form_data[ 'id' ] ) !== 879 ) { return; } remove_action( 'wpforms_display_field_before', array( wpforms()->frontend, 'field_label' ), 15, 2 ); } add_action( 'wpforms_display_field_before', 'wpf_dev_display_field_before', 10, 2 );