Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a multisite and need a function (added to functions.php) that will get the template url of the second theme (probably by name or other identifier)?

Example: theme-1 (used by main site) contains function to get url of theme-2 (theme-2 is used by sub-sites)

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can use two inbuilt functions to do this.

  1. switch_to_blog
  2. get_stylesheet_directory_uri

You can use both in the following way to make a function out of it which would give you the url to the theme. Put the below in the functions.php file

function wpse_get_theme_url( $blog_id = 1 ){
    switch_to_blog( $blog_id );

    $template_url = get_stylesheet_directory_uri();
    restore_current_blog(); // Switch back to the original blog

    return $template_url;
}

Now you can use the above function to fetch the url by using the function and passing the blog id/ sub site id.

$theme_url = wpse_get_theme_url( $blog_id );
// Replace the $blog_id with blog id of your sub sites.
share|improve this answer
1  
Thank you very much, that worked well!! –  Alexnl Nov 26 '13 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.