开发者

Replace https with http in wp_nav_menu

I want to replace all links in my main menu with http whenever they are https

I have tried the function below but it has no effect

function wp_list_pages_custom() {
   $array = array();
   $pages = wp_nav_menu( array( 
      'menu'            => 'Main Menu', 
      'menu_id'         => 'menu',  
      'echo'            => true,
      'fallback_cb'     => 'wp开发者_运维百科_page_menu',
      'before'          => '',
      'after'           => '',
      'depth'           => 0
   ));
   $pages = str_replace('https', 'http', $pages);
   echo $pages;
}


function wp_list_pages_custom() {

$array = array();

$pages = wp_nav_menu( array( 
  'menu'            => 'Main Menu', 
  'menu_id'         => 'menu',  
  'echo'            => false,
  'fallback_cb'     => 'wp_page_menu',
  'before'          => '',
  'after'           => '',
  'depth'           => 0
));

$pages = str_replace('https', 'http', $pages);

echo $pages;

}

you had echo true, so the function handles the output


According to the documentation of wp_nav_menu, the echo parameter needs to be false in order to get the menu just returned instead of printed. So currently you probably have the menu printed twice. You should also check whether the method returns absolute URLs or relative URLs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜