wppaste
WordPress

submit_button( string $text = '', string $type = 'primary', string $name = 'submit', bool $wrap = true, array|string $other_attributes = '' )

Since
3.1.0
Source
wp-admin/includes/template.php:2559

Prints a ready-made <input type="submit"> for admin screens, choosing its CSS classes from $type ('primary', 'small', 'compact' or 'large') and its name/id from $name. It echoes the markup immediately rather than returning it, so use get_submit_button() when you need the HTML as a string to filter or insert elsewhere. It's the same button markup WordPress uses for Save Changes on settings pages, post list table bulk actions, and screen options.

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

Compatibility

WordPress
since 3.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$textstringoptional
The text of the button. Defaults to 'Save Changes'.Default: ''
$typestringoptional
The type and CSS class(es) of the button. Core values include 'primary', 'small', and 'large'. Default 'primary'.Default: 'primary'
$namestringoptional
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'.Default: 'submit'
$wrapbooloptional
True if the output button should be wrapped in a paragraph tag, false otherwise. Default true.Default: true
$other_attributesarray|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 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.Default: ''

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Print a save button and an unwrapped secondary button

Show the default wrapped primary button next to one with $wrap set to false so it doesn't get its own paragraph.

submit_button();

submit_button( 'Publish Draft', 'secondary', 'publish-draft', false );
echo ' ';
echo esc_html( 'unwrapped button above has no surrounding <p>' );

The first call wraps its <input> in a <p class="submit"> tag because $wrap defaults to true; the second does not.

Put two buttons on one line with a custom id via $other_attributes

Combine a save button and a reset button inside a single paragraph, giving the second one an explicit id since it isn't named 'submit'.

echo '<p>';
submit_button( 'Save Changes', 'primary', 'submit', false );
echo ' ';
submit_button(
	'Reset Filters',
	'secondary small',
	'reset-filters',
	false,
	array(
		'id'    => 'meta-box-reset',
		'style' => 'margin-left:8px;',
	)
);
echo '</p>';

Without the 'id' key in $other_attributes, the second button's id would default to its $name value, 'reset-filters'.

Common problems and fixes · 3

Why does assigning submit_button() to a variable give me null?

submit_button() calls echo get_submit_button( ... ) internally and has no return statement, so it always outputs to the page and gives back null.

Why is my button missing its surrounding <p> tag?

The paragraph wrapper is controlled entirely by $wrap. Passing false, or reusing code that hardcodes false for a shared row of buttons, removes the

element.

Why do two buttons on the same page end up with the same id and break my JavaScript selector?

When $other_attributes has no 'id' key, the button's id falls back to $name, and $name defaults to 'submit' for every call. Calling submit_button() twice without changing $name produces two elements with id="submit".

Alternatives and related functions

get_submit_button
When you need the button markup as a string, for example to filter it or splice it into a larger HTML buffer instead of echoing it right away.

Performance profile

How much work a call to submit_button() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
14

Executed per call on PHP 8.5. The body compiles to 14.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
43

43 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost submit_button() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always14get_submit_button()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 14 instructions, 14 executed per call, 0 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

Used by · 43

Show all 43

Source code

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

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-admin/includes/template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.