0

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?

1
  • "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, 2013 at 18:49

1 Answer 1

1

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.

2
  • 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. Nov 16, 2013 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. Nov 16, 2013 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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