submit_button()WP 3.1.0

Echoes a submit button, with provided text and appropriate class(es).

1 time — 0.000053 sec (very fast) | 50000 times — 1.39 sec (fast)

No Hooks.

Return

null. Nothing (null).

Usage

submit_button( $text, $type, $name, $wrap, $other_attributes );
$text(string)
The text of the button.
Default: 'Save Changes'
$type(string)
The type and CSS class(es) of the button. Core values include 'primary', 'small', and 'large'.
Default: 'primary'
$name(string)
The HTML name of the submit button. If no id attribute is given in the $other_attributes parameter, $name will be used as the button's id.
Default: 'submit'
$wrap(true|false)
True if the output button should be wrapped in a paragraph tag, false otherwise.
Default: true
$other_attributes(array|string)
Other attributes that should be output with the button, mapping attributes to their values, e.g. array('id'=>'search-submit'). These key/value attribute pairs will be output as attribute="value", where attribute is the key. Attributes can also be provided as a string, e.g. id="search-submit", though the array format is generally preferred.
Default: empty string

Examples

0

#1 Demo

submit_button( 'Apply', 'action', '', false, [ 'id' => 'doaction2' ] );

// output:
// <input type="submit" id="doaction2" class="action button" value="Apply">
0

#2 Secondary button display

WordPress designs the main button and the additional button differently. The main button is blue and stands out more, the additional button is gray and is not as eye-catching.

By default, submit_button() outputs the main button. To display a secondary button instead, set $type = 'secondary':

submit_button( __( 'Reset', 'textdomain' ), 'secondary' );
0

#3 Displaying the delete button

By default, there are no styles for the delete button in WordPress. However, this may change in the future, so it's best to specify $type as 'delete' when displaying the delete button:

submit_button( __( 'Delete', 'textdomain' ), 'delete' );

By default, the delete button is styled as a secondary button, not the primary button. If you want to display it as a primary button, you can do it as follows:

submit_button( __( 'Delete', 'textdomain' ), 'delete button-primary' );
0

#4 Using the $name Parameter

The parameter $name can be used if you want to set the HTML attribute name for the button. The default value there is submit.

submit_button( __( 'Save Settings', 'textdomain' ), 'primary', 'wpdocs-save-settings' );

By default, $name is also used to fill the attribute id of the button. To change this, you can pass id through the parameter $other_attributes:

$other_attributes = [ 'id' => 'wpdocs-button-id' ];
submit_button( __( 'Save', 'textdomain' ), 'primary', 'wpdocs-save-settings', true, $other_attributes );
0

#5 Using the $wrap parameter

The $wrap parameter determines whether the button is wrapped in the <p> tag, which is the default. To disable this behavior, pass false for the fourth parameter:

submit_button( __( 'Submit', 'textdomain' ), 'primary', 'submit-form', false );
0

#6 Specifying other HTML attributes

You can add any HTML attributes for the button - using the $other_attributes parameter:

$other_attributes = [ 'tabindex' => '1' ];
submit_button( __( 'Go!', 'textdomain' ), 'secondary', '', true, $other_attributes );

Notes

Changelog

Since 3.1.0 Introduced.

submit_button() code WP 6.5.2

function submit_button( $text = '', $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = '' ) {
	echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
}