admin管理员组文章数量:1122832
I'm using this function to switch to my main website's navigation and display it on all sub sites in my multisite network. Ideally the links should have the following format:
but on the sub-sites the urls are
Obviously these pages don't exist so it's just showing a blank page. Any idea how I could make sure the urls are like the first example and how I might incorporate that into my function?
function wp_multisite_nav_menu() {
global $blog_id;
$args = array(
'menu' => 'Main Menu',
'theme_location' => 'main-nav'
);
$main_blog = 1;
$main_blog = absint( $main_blog );
if ( !is_multisite() || $blog_id == $main_blog ) {
echo wp_nav_menu( $args );
return;
}
else {
switch_to_blog( 1 );
echo wp_nav_menu( $args );
restore_current_blog();
}
}
I'm using this function to switch to my main website's navigation and display it on all sub sites in my multisite network. Ideally the links should have the following format:
http://www.mysite.com/navigation-link
but on the sub-sites the urls are http://www.mysite.com/subsite/navigation-link
Obviously these pages don't exist so it's just showing a blank page. Any idea how I could make sure the urls are like the first example and how I might incorporate that into my function?
function wp_multisite_nav_menu() {
global $blog_id;
$args = array(
'menu' => 'Main Menu',
'theme_location' => 'main-nav'
);
$main_blog = 1;
$main_blog = absint( $main_blog );
if ( !is_multisite() || $blog_id == $main_blog ) {
echo wp_nav_menu( $args );
return;
}
else {
switch_to_blog( 1 );
echo wp_nav_menu( $args );
restore_current_blog();
}
}
Share
Improve this question
asked Apr 9, 2014 at 12:05
chapchap
3581 gold badge4 silver badges19 bronze badges
1 Answer
Reset to default 0You just need the last part of your function where you switch to blog 1 and get the menu.
function wp_multisite_nav_menu() {
$args = [
'menu' => 'Main Menu',
'theme_location' => 'main-nav'
];
switch_to_blog( 1 );
echo wp_nav_menu( $args );
restore_current_blog();
}
本文标签: functionsHow to get correct URLs in network wide menu (Multisite)
版权声明:本文标题:functions - How to get correct URLs in network wide menu (Multisite)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283249a1926907.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论