Title: maybe_drop_column
Published: September 4, 2014
Last modified: February 24, 2026

---

# maybe_drop_column( string $table_name, string $column_name, string $drop_ddl ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#wp--skip-link--target)

Drops column from database table, if it exists.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#parameters)󠁿

 `$table_name`stringrequired

Database table name.

`$column_name`stringrequired

Table column name.

`$drop_ddl`stringrequired

SQL statement to drop column.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#return)󠁿

 bool True on success or if the column doesn’t exist. False on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#source)󠁿

    ```php
    function maybe_drop_column( $table_name, $column_name, $drop_ddl ) {
    	global $wpdb;

    	// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
    	foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    		if ( $column === $column_name ) {

    			// Found it, so try to drop it.
    			// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
    			$wpdb->query( $drop_ddl );

    			// We cannot directly tell whether this succeeded!
    			// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
    			foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    				if ( $column === $column_name ) {
    					return false;
    				}
    			}
    		}
    	}

    	// Else didn't find it.
    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/install-helper.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/install-helper.php#L129)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/install-helper.php#L129-L152)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#related)󠁿

| Uses | Description | 
| [wpdb::get_col()](https://developer.wordpress.org/reference/classes/wpdb/get_col/)`wp-includes/class-wpdb.php` |

Retrieves one column from the database.

  | 
| [wpdb::query()](https://developer.wordpress.org/reference/classes/wpdb/query/)`wp-includes/class-wpdb.php` |

Performs a database query, using current database connection.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/maybe_drop_column/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.0.0](https://developer.wordpress.org/reference/since/1.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fmaybe_drop_column%2F)
before being able to contribute a note or feedback.