Echoes a submit button, with provided text and appropriate class(es).
Description
See also
Parameters
$text
stringoptional- The text of the button. Defaults to ‘Save Changes’.
Default:
''
$type
stringoptional- The type and CSS class(es) of the button. Core values include
'primary'
,'small'
, and'large'
. Default'primary'
.Default:
'primary'
$name
stringoptional- 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’sid
. Default'submit'
.Default:
'submit'
$wrap
booloptional- True if the output button should be wrapped in a paragraph tag, false otherwise.
Default:
true
$other_attributes
array|stringoptional- 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 asattribute="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:
''
Source
echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
}
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
Default Usage
This will output the following HTML, which will display a button with the text “Save Changes”.
Display a Secondary Button
WordPress styles secondary and primary buttons differently. Primary buttons are blue, and stand out more than secondary buttons, which are grey. By default,
submit_button()
outputs a primary button. To display a secondary button instead, set the$type
parameter to'secondary'
:Display a Delete Button
By default, WordPress doesn’t currently appear to have custom styling for delete buttons, but it does give them the
'delete'
HTML class. However, it’s possible that could change in the future, so it’s a good idea to specify the$type
as'delete'
when displaying a delete button:By default, delete buttons will be displayed as secondary buttons, not primary. If you want to display it as a primary button, you can do it like this:
Using the $name Parameter
The
$name
parameter may be used if you want to set the HTML name attribute for the button. By default, this will be'submit'
.By default, the
$name
is also used to fill out the button’sid
attribute. To change this, you can pass anid
via the$other_attributes
parameter:Using the $wrap Parameter
The
$wrap
parameter controls whether the button is wrapped in a paragraph tag, which it is by default. This can be a help or a hindrance depending on where an how you wish to display the button. To turn this behavior off, passfalse
for the fourth parameter:Specifying Other HTML Attributes
You can add any HTML attributes you chose to your button using the
$other_attributes
parameter. For example:Using Custom Text
To output a button with custom text, use the first parameter like this:
This example shows a plugin options page form with two submit buttons, each serving different purposes.