我有一个多站点,需要一个函数(添加到functions.php)来获取第二个主题的模板url(可能通过名称或其他标识符)?
示例:theme-1(由主站点使用)包含获取theme-2 url的函数(theme-2由子站点使用)
谢谢
我有一个多站点,需要一个函数(添加到functions.php)来获取第二个主题的模板url(可能通过名称或其他标识符)?
示例:theme-1(由主站点使用)包含获取theme-2 url的函数(theme-2由子站点使用)
谢谢
可以使用两个内置函数来执行此操作。
您可以通过以下方式使用这两种方法来生成一个函数,该函数将为您提供主题的url。将下面的functions.php
文件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;
}
现在,您可以使用上述函数获取url,方法是使用该函数并传递博客id/子站点id。$theme_url = wpse_get_theme_url( $blog_id );
// Replace the $blog_id with blog id of your sub sites.
所以我想更改我的上传目录。我可以通过以下方式进行更改:add_filter( \'pre_option_upload_url_path\', \'wpse_77960_upload_url\' ); function wpse_77960_upload_url() { return \'http://subdomain.example.com/files\'; } 或update_option(\'upload_url_path\', \'/wp-content/up