Title: wp_print_theme_file_tree
Published: November 20, 2017
Last modified: May 20, 2026

---

# wp_print_theme_file_tree( array|string $tree, int $level = 2, int $size = 1, int $index = 1 )

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Outputs the formatted file list for the theme file editor.

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

 `$tree`array|stringrequired

List of file/folder paths, or filename.

`$level`intoptional

The aria-level for the current iteration.

Default:`2`

`$size`intoptional

The aria-setsize for the current iteration.

Default:`1`

`$index`intoptional

The aria-posinset for the current iteration.

Default:`1`

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

    ```php
    function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
    	global $relative_file, $stylesheet;

    	if ( is_array( $tree ) ) {
    		$index = 0;
    		$size  = count( $tree );

    		foreach ( $tree as $label => $theme_file ) :
    			++$index;

    			if ( ! is_array( $theme_file ) ) {
    				wp_print_theme_file_tree( $theme_file, $level, $index, $size );
    				continue;
    			}
    			?>
    			<li role="treeitem" aria-expanded="true" tabindex="-1"
    				aria-level="<?php echo esc_attr( $level ); ?>"
    				aria-setsize="<?php echo esc_attr( $size ); ?>"
    				aria-posinset="<?php echo esc_attr( $index ); ?>">
    				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text">
    					<?php
    					/* translators: Hidden accessibility text. */
    					_e( 'folder' );
    					?>
    				</span><span aria-hidden="true" class="icon"></span></span>
    				<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul>
    			</li>
    			<?php
    		endforeach;
    	} else {
    		$filename = $tree;
    		$url      = add_query_arg(
    			array(
    				'file'  => rawurlencode( $tree ),
    				'theme' => rawurlencode( $stylesheet ),
    			),
    			self_admin_url( 'theme-editor.php' )
    		);
    		?>
    		<li role="none" class="<?php echo esc_attr( $relative_file === $filename ? 'current-file' : '' ); ?>">
    			<a role="treeitem" tabindex="<?php echo esc_attr( $relative_file === $filename ? '0' : '-1' ); ?>"
    				href="<?php echo esc_url( $url ); ?>"
    				aria-level="<?php echo esc_attr( $level ); ?>"
    				aria-setsize="<?php echo esc_attr( $size ); ?>"
    				aria-posinset="<?php echo esc_attr( $index ); ?>">
    				<?php
    				$file_description = esc_html( get_file_description( $filename ) );

    				if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) {
    					$file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
    				}

    				if ( $relative_file === $filename ) {
    					echo '<span class="notice notice-info">' . $file_description . '</span>';
    				} else {
    					echo $file_description;
    				}
    				?>
    			</a>
    		</li>
    		<?php
    	}
    }
    ```

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

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

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

Outputs the formatted file list for the theme file editor.

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

Gets the description for standard WordPress theme files.

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

Retrieves the URL to the admin area for either the current site or the network depending on context.

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

Displays translated text.

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

i18n-friendly version of basename().

  | 
| [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.

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

Checks and cleans a URL.

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

Retrieves a modified URL query string.

  |

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

| Used by | Description | 
| [wp_print_theme_file_tree()](https://developer.wordpress.org/reference/functions/wp_print_theme_file_tree/)`wp-admin/includes/misc.php` |

Outputs the formatted file list for the theme file editor.

  |

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

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

## User Contributed Notes

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