WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just tried installing my theme on another WP install that lies in a subdirectory of the domain. I never really thought too hard about subdirectories, but it does happen so I know I need to change it. Absolute URLS aren't feasible since I plan on distributing the theme.

The catch here is that the URL needs to work inside of an array more specifically with some themes settings. Here is how they look.

function mytheme_get_theme_mods() {
    $defaults = array(
        'mytheme_header_logo'  => '/wp-content/themes/mytheme/img/logo.png',
        'mytheme_footer_logo'  => '/wp-content/themes/mytheme/img/footerlogo.png',
        'mytheme_middle_image' => '/wp-content/themes/mytheme/img/middleimg.png'
    return $defaults;

Can anyone help me out?

share|improve this question
"Absolute URLS aren't feasible since I plan on distributing the theme." -- this is false. If you use the appropriate Core functions to locate your files there will be no problem. – s_ha_dum Nov 16 '13 at 18:49
up vote 1 down vote accepted

Make use of the functions wordpress offers to determine paths and URLs - see Determining Plugin and Content Directories. For example use:

You find more information on the linked codex page about determining directories.

Edit: In response to the comment.

This is how I'd do it:

function mytheme_get_theme_mods() {
    $tpl_dir_pth = get_template_directory();
    $defaults = array(
        'mytheme_header_logo' => $tpl_dir_pth . '/img/logo.png',
        'mytheme_footer_logo' => $tpl_dir_pth . '/img/footerlogo.png',
        'mytheme_middle_image' => $tpl_dir_pth . '/img/middleimg.png'

    return $defaults;

Of course I don't know if the absolute path actually is what you want.

share|improve this answer
get_template_directory was the first approach I tried. Although it doesn't work when in the array value. Or atleast the ways I tried it. – user1632018 Nov 16 '13 at 18:14
Using get_template_directory seems to give me my ftp folders before the domain aswell. Not sure why as I don't have any rewrite functions. I tried get_template_directory_uri and it ended up working. I have to admit, my previous attempt I added the code between ' '. Thanks. – user1632018 Nov 16 '13 at 18:47

Your Answer


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.