Title: update_gallery_tab
Published: April 25, 2014
Last modified: April 28, 2025

---

# update_gallery_tab( array $tabs ): array

## In this article

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

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

Adds the gallery tab back to the tabs array if post has image attachments.

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

 `$tabs`arrayrequired

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

 array $tabs with gallery if post has image attachment

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

    ```php
    function update_gallery_tab( $tabs ) {
    	global $wpdb;

    	if ( ! isset( $_REQUEST['post_id'] ) ) {
    		unset( $tabs['gallery'] );
    		return $tabs;
    	}

    	$post_id = (int) $_REQUEST['post_id'];

    	if ( $post_id ) {
    		$attachments = (int) $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) );
    	}

    	if ( empty( $attachments ) ) {
    		unset( $tabs['gallery'] );
    		return $tabs;
    	}

    	/* translators: %s: Number of attachments. */
    	$tabs['gallery'] = sprintf( __( 'Gallery (%s)' ), "<span id='attachments-count'>$attachments</span>" );

    	return $tabs;
    }
    ```

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

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

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

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

Retrieves one value from the database.

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

Prepares a SQL query for safe execution.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/update_gallery_tab/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/update_gallery_tab/?output_format=md#)

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

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

## User Contributed Notes

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