WP_Widget::get_field_id() WordPress Method
The WP_Widget::get_field_id() method allows you to retrieve the HTML ID for a given field. This can be useful for targeting specific fields with CSS or JavaScript.
WP_Widget::get_field_id( string $field_name ) #
Constructs id attributes for use in WP_Widget::form() fields.
Description
This function should be used in form() methods to create id attributes for fields to be saved by WP_Widget::update().
Parameters
- $field_name
(string)(Required)Field name.
Return
(string) ID attribute for $field_name
.
Source
File: wp-includes/class-wp-widget.php
public function get_field_id( $field_name ) { $field_name = str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ); $field_name = trim( $field_name, '-' ); return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.4.0 | Array format field IDs are now accepted. |
2.8.0 | Introduced. |