Title: do_accordion_sections
Published: April 25, 2014
Last modified: February 24, 2026

---

# do_accordion_sections( string|object $screen, string $context, mixed $data_object ): int

## In this article

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

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

Meta Box Accordion Template Function.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/do_accordion_sections/?output_format=md#description)󠁿

Largely made up of abstracted code from [do_meta_boxes()](https://developer.wordpress.org/reference/functions/do_meta_boxes/),
this function serves to build meta boxes as list items for display as a collapsible
accordion.

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

 `$screen`string|objectrequired

The screen identifier.

`$context`stringrequired

The screen context for which to display accordion sections.

`$data_object`mixedrequired

Gets passed to the section callback function as the first parameter.

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

 int Number of meta boxes as accordion sections.

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

    ```php
    function do_accordion_sections( $screen, $context, $data_object ) {
    	global $wp_meta_boxes;

    	wp_enqueue_script( 'accordion' );

    	if ( empty( $screen ) ) {
    		$screen = get_current_screen();
    	} elseif ( is_string( $screen ) ) {
    		$screen = convert_to_screen( $screen );
    	}

    	$page = $screen->id;

    	$hidden = get_hidden_meta_boxes( $screen );
    	?>
    	<div id="side-sortables" class="accordion-container">
    		<ul class="outer-border">
    	<?php
    	$i          = 0;
    	$first_open = false;

    	if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
    		foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
    			if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
    				foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
    					if ( false === $box || ! $box['title'] ) {
    						continue;
    					}

    					++$i;
    					$hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : '';

    					$open_class    = '';
    					$aria_expanded = 'false';
    					if ( ! $first_open && empty( $hidden_class ) ) {
    						$first_open    = true;
    						$open_class    = 'open';
    						$aria_expanded = 'true';
    					}
    					?>
    					<li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
    						<h3 class="accordion-section-title hndle">
    							<button type="button" class="accordion-trigger" aria-expanded="<?php echo $aria_expanded; ?>" aria-controls="<?php echo esc_attr( $box['id'] ); ?>-content">
    								<span class="accordion-title">
    									<?php echo esc_html( $box['title'] ); ?>
    									<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span>
    								</span>
    							</button>
    						</h3>
    						<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>-content">
    							<div class="inside">
    								<?php call_user_func( $box['callback'], $data_object, $box ); ?>
    							</div><!-- .inside -->
    						</div><!-- .accordion-section-content -->
    					</li><!-- .accordion-section -->
    					<?php
    				}
    			}
    		}
    	}
    	?>
    		</ul><!-- .outer-border -->
    	</div><!-- .accordion-container -->
    	<?php
    	return $i;
    }
    ```

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

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

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

Get the current screen object

  | 
| [get_hidden_meta_boxes()](https://developer.wordpress.org/reference/functions/get_hidden_meta_boxes/)`wp-admin/includes/screen.php` |

Gets an array of IDs of hidden meta boxes.

  | 
| [convert_to_screen()](https://developer.wordpress.org/reference/functions/convert_to_screen/)`wp-admin/includes/template.php` |

Converts a screen string to a screen object.

  | 
| [postbox_classes()](https://developer.wordpress.org/reference/functions/postbox_classes/)`wp-admin/includes/post.php` |

Returns the list of classes to be used by a meta box.

  | 
| [wp_enqueue_script()](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)`wp-includes/functions.wp-scripts.php` |

Enqueues a script.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  |

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

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

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

## User Contributed Notes

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