开发者

Replace https with http in wp_nav_menu

开发者 https://www.devze.com 2023-03-03 07:11 出处:网络
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

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

精彩评论

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