如何确保当网站不在根域上时相对 URL 正常工作


How to make sure relative URL works when site is not on root domain?

我刚刚尝试在位于域子目录中的另一个 WP 安装上安装我的主题。我从来没有真正考虑过子目录,但它确实发生了,所以我知道我需要改变它。绝对 URL 是不可行的,因为我计划分发主题。

这里的问题是 URL 需要更具体地在数组内部使用某些主题设置。这是它们的外观。

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;

}

谁能帮我?

试试这个:

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

如果您喜欢查看数组的输出位置 'print_r($defaults);' 在 return 下方,然后在 index 中调用函数.php它将打印查找图像的确切 URL。