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:2570
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.
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
idattribute is given in the$other_attributesparameter,$namewill be used as the button'sid. 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 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 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?
- Why is my button missing its surrounding <p> tag?
- Why do two buttons on the same page end up with the same id and break my JavaScript selector?
Why does assigning submit_button() to a variable give me null?
Why is my button missing its surrounding <p> tag?
element.
Why do two buttons on the same page end up with the same id and break my JavaScript selector?
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
- Scaling
- Constant
- Instructions
- 14
- Plugin surface
- None
- Called by
- 43
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 14.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14 | get_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
- get_submit_button()Returns a submit button, with provided text and appropriate class.
Used by · 43
- Custom_Background::admin_page()Displays the custom background page.
- Custom_Image_Header::step_1()Displays first step of custom header image page.
- Custom_Image_Header::step_2()Displays second step of custom header image page.
- WP_Comments_List_Table::extra_tablenav()
- WP_Links_List_Table::extra_tablenav()
- WP_List_Table::bulk_actions()Displays the bulk actions dropdown.
- WP_List_Table::search_box()Displays the search box.
- WP_MS_Sites_List_Table::extra_tablenav()Displays extra controls between bulk actions and pagination.
- WP_Media_List_Table::extra_tablenav()
- WP_Plugins_List_Table::extra_tablenav()
- WP_Plugins_List_Table::search_box()Displays the search box.
- WP_Posts_List_Table::extra_tablenav()
Show all 43
- WP_Posts_List_Table::inline_edit()Outputs the hidden row displayed when inline editing
- WP_Screen::render_screen_options()Renders the screen options tab.
- WP_Users_List_Table::extra_tablenav()Outputs the controls to allow user roles to be changed in bulk.
- _wp_dashboard_control_callback()Outputs controls for the current dashboard widget.
- attachment_submit_meta_box()Displays attachment submit form fields.
- confirm_delete_users()
- display_setup_form()Displays installer setup form.
- find_posts_div()Outputs the modal window used for attaching media to posts or pages in the media-listing screen.
- install_plugins_upload()Displays a form to upload plugins from zip files.
- install_search_form()Displays a search form for searching plugins.
- install_theme_search_form()Displays search form for searching themes.
- install_themes_dashboard()Displays tags filter for themes.
- install_themes_upload()Displays a form to upload themes from zip files.
- link_submit_meta_box()Displays link create form fields.
- list_core_update()Lists available core updates.
- media_upload_form()Outputs the legacy media upload form.
- media_upload_gallery_form()Adds gallery form to upload iframe.
- media_upload_library_form()Outputs the legacy media upload form for the media library.
- media_upload_type_form()Outputs the legacy media upload form for a given media type.
- meta_form()Prints the form in the Custom Fields meta box.
- network_step1()Prints step 1 for Network installation process.
- post_submit_meta_box()Displays post submit form fields.
- request_filesystem_credentials()Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
- twentyeleven_theme_options_render_page()Renders the theme options page for Twenty Eleven.
- wp_dashboard_quick_press()Displays the Quick Draft widget.
- wp_import_upload_form()Outputs the form used by the importers to accept the data to be imported.
- wp_nav_menu_item_post_type_meta_box()Displays a meta box for a post type menu item.
- wp_nav_menu_item_taxonomy_meta_box()Displays a meta box for a taxonomy menu item.
- wp_network_dashboard_right_now()
- wp_print_community_events_markup()Prints the markup for the Community Events section of the Events and News Dashboard widget.
- wp_widget_control()Meta widget used to display the control form for a widget.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.