get_submit_button

The timeline below displays how wordpress function get_submit_button has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Returns a submit button, with provided text and appropriate class.
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Defaults to 'Save Changes'.
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
 * @param string       $name             Optional. 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'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph tag,
 *                                       false otherwise. Default true.
 * @param array|string $other_attributes Optional. 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.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand, true) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes.
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important.
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string.
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 6.1

/**
 * Returns a submit button, with provided text and appropriate class.
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand, true) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes.
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important.
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string.
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 5.5

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand, true) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes.
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important.
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string.
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 5.4

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes.
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important.
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string.
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 4.8

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 4.7

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type of button. Accepts 'primary', 'secondary',
 *                                       or 'delete'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand) ? 'button-' . $t : $t;
    }
    // Remove empty items, remove duplicate items, and finally build a string.
    $class = implode(' ', array_unique(array_filter($classes)));
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 4.2

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
 * @param string       $type             Optional. The type of button. Accepts 'primary', 'secondary',
 *                                       or 'delete'. Default 'primary large'.
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
 *                                       If no id attribute is given in $other_attributes below, `$name` will
 *                                       be used as the button's id. Default 'submit'.
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
 *                                       tag, false otherwise. Default true.
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
 *                                       These attributes will be output as `attribute="value"`, such as
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
 *                                       Default empty.
 * @return string Submit button HTML.
 */
function get_submit_button($text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '')
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand) ? 'button-' . $t : $t;
    }
    $class = implode(' ', array_unique($classes));
    if ('delete' === $type) {
        $class = 'button-secondary delete';
    }
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important
        }
    } elseif (!empty($other_attributes)) {
        // Attributes provided as a string
        $attributes = $other_attributes;
    }
    // Don't output empty name and id attributes.
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}

WordPress Version: 3.7

/**
 * Returns a submit button, with provided text and appropriate class
 *
 * @since 3.1.0
 *
 * @param string $text The text of the button (defaults to 'Save Changes')
 * @param string $type The type of button. One of: primary, secondary, delete
 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
 *               is given in $other_attributes below, $name will be used as the button's id.
 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
 * 			   false otherwise. Defaults to true
 * @param array|string $other_attributes Other attributes that should be output with the button,
 *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
 *                     These attributes will be output as attribute="value", such as tabindex="1".
 *                     Defaults to no other attributes. Other attributes can also be provided as a
 *                     string such as 'tabindex="1"', though the array format is typically cleaner.
 */
function get_submit_button($text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null)
{
    if (!is_array($type)) {
        $type = explode(' ', $type);
    }
    $button_shorthand = array('primary', 'small', 'large');
    $classes = array('button');
    foreach ($type as $t) {
        if ('secondary' === $t || 'button-secondary' === $t) {
            continue;
        }
        $classes[] = in_array($t, $button_shorthand) ? 'button-' . $t : $t;
    }
    $class = implode(' ', array_unique($classes));
    if ('delete' === $type) {
        $class = 'button-secondary delete';
    }
    $text = $text ? $text : __('Save Changes');
    // Default the id attribute to $name unless an id was specifically provided in $other_attributes
    $id = $name;
    if (is_array($other_attributes) && isset($other_attributes['id'])) {
        $id = $other_attributes['id'];
        unset($other_attributes['id']);
    }
    $attributes = '';
    if (is_array($other_attributes)) {
        foreach ($other_attributes as $attribute => $value) {
            $attributes .= $attribute . '="' . esc_attr($value) . '" ';
            // Trailing space is important
        }
    } else if (!empty($other_attributes)) {
        // Attributes provided as a string
        $attributes = $other_attributes;
    }
    $button = '<input type="submit" name="' . esc_attr($name) . '" id="' . esc_attr($id) . '" class="' . esc_attr($class);
    $button .= '" value="' . esc_attr($text) . '" ' . $attributes . ' />';
    if ($wrap) {
        $button = '<p class="submit">' . $button . '</p>';
    }
    return $button;
}