Title: get_theme_file_uri
Published: December 6, 2016
Last modified: February 24, 2026

---

# get_theme_file_uri( string $file ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#user-contributed-notes)

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

Retrieves the URL of a file in the theme.

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

Searches in the stylesheet directory before the template directory so themes which
inherit from a parent theme can just override one file.

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

 `$file`stringoptional

File to search for in the stylesheet directory.

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

 string The URL of the file.

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

    ```php
    function get_theme_file_uri( $file = '' ) {
    	$file = ltrim( $file, '/' );

    	$stylesheet_directory = get_stylesheet_directory();

    	if ( empty( $file ) ) {
    		$url = get_stylesheet_directory_uri();
    	} elseif ( get_template_directory() !== $stylesheet_directory && file_exists( $stylesheet_directory . '/' . $file ) ) {
    		$url = get_stylesheet_directory_uri() . '/' . $file;
    	} else {
    		$url = get_template_directory_uri() . '/' . $file;
    	}

    	/**
    	 * Filters the URL to a file in the theme.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param string $url  The file URL.
    	 * @param string $file The requested file to search for.
    	 */
    	return apply_filters( 'theme_file_uri', $url, $file );
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#hooks)󠁿

 [apply_filters( ‘theme_file_uri’, string $url, string $file )](https://developer.wordpress.org/reference/hooks/theme_file_uri/)

Filters the URL to a file in the theme.

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

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

Retrieves stylesheet directory path for the active theme.

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

Retrieves stylesheet directory URI for the active theme.

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

Retrieves template directory path for the active theme.

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

Retrieves template directory URI for the active theme.

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

Calls the callback functions that have been added to a filter hook.

  |

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

| Used by | Description | 
| [WP_Theme_JSON_Resolver::get_resolved_theme_uris()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_resolved_theme_uris/)`wp-includes/class-wp-theme-json-resolver.php` |

Resolves relative paths in theme.json styles to theme absolute paths and returns them in an array that can be embedded as the value of `_link` object in REST API responses.

  | 
| [WP_Font_Face_Resolver::to_theme_file_uri()](https://developer.wordpress.org/reference/classes/wp_font_face_resolver/to_theme_file_uri/)`wp-includes/fonts/class-wp-font-face-resolver.php` |

Converts each ‘file:./’ placeholder into a URI to the font file in the theme.

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

Gets the URL to a block asset.

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

Runs the theme.json webfonts handler.

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

Creates an array of theme styles to load into the block editor.

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#comment-content-5967)
 2.    [Marcio Duarte](https://profiles.wordpress.org/pagelab/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_theme_file_uri/#comment-5967)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%23comment-5967)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%23comment-5967)
 4.  You can use this function to include local theme assets (like images) in your 
     block patterns:
 5.      ```php
         <!-- wp:image {"id":12,"width":640,"height":400,"sizeSlug":"full","linkDestination":"none"} -->
         <figure class="wp-block-image size-full"><img src="<?php
         echo esc_url( get_theme_file_uri( 'assets/img/my-asset.png' ) ); ?>" alt="<?php _e( 'Asset description' ) ?>" width="640" height="400"/></figure>
         <!-- /wp:image -->
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%3Freplytocom%3D5967%23feedback-editor-5967)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_theme_file_uri/?output_format=md#comment-content-3476)
 8.    [Marcio Zebedeu](https://profiles.wordpress.org/marcio-zebedeu/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_theme_file_uri/#comment-3476)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%23comment-3476)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%23comment-3476)
 10. a simple example
 11.     ```php
         wp_enqueue_style ( 'custom-font-awesome', get_theme_file_uri('/css/all.min.css'), array () );
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_theme_file_uri%2F%3Freplytocom%3D3476%23feedback-editor-3476)

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