Title: Absolute js path to theme?
Last modified: August 22, 2016

---

# Absolute js path to theme?

 *  [brian914](https://wordpress.org/support/users/brian914/)
 * (@brian914)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/absolute-js-path-to-theme/)
 * I am looking for a way to get a url to the theme to be used with my javascrpt.
   I am using requirejs and need a baseUrl.
 * I thought I could do something like this in my functions file:
 *     ```
       function init_themeRootReference(){
       	// Set up js varibale for root directory
       	$my_theme_dir = array( 'path' => get_stylesheet_directory_uri() );
       	wp_localize_script( 'my-dependent', 'themeRootReference', $my_theme_dir );
       }
       add_action( 'after_setup_theme', 'init_themeRootReference' );
       ```
   
 * And then get that in my js file like so:
    `baseUrl = themeRootReference.path`
 * I think the problem I am having is that the js fires before the add_action() 
   call and so the variable in js is undefined. Is there an action in WordPress 
   that comes sooner? Or are there other ways I can set this up?
 * Thank you very much for any help with this!!!

The topic ‘Absolute js path to theme?’ is closed to new replies.

## Tags

 * [add_action](https://wordpress.org/support/topic-tag/add_action/)
 * [theme setup](https://wordpress.org/support/topic-tag/theme-setup/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [brian914](https://wordpress.org/support/users/brian914/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/absolute-js-path-to-theme/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
