douchen2025 2019-01-14 09:45
浏览 82
已采纳

如何使用WordPress Avada子主题将主徽标的链接更改为自定义URL而不是主页?

I am trying to change the logo link for specific pages, so that it will link to a custom URL for specific page.

I tried to add this code that I found also here in stackoverflow. This works fine on page "169" the logo link point to https://sampleurl.com/page-1/.

//This is for page-1
add_filter('avada_logo_anchor_tag_attributes', 'broadway_logo_link_modify');
function broadway_logo_link_modify() {

  $link = esc_url( home_url( '/' ) );

  if (is_page( array (169))) {
    $link = 'https://sampleurl.com/page-1/';
  }

  // another option with which you don't have to add every page id
  $current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  if (strpos($current_url, 'https://sampleurl.com/page-1/') !== false) {
    $link = 'https://sampleurl.com/page-1/';
  }

  $link_arr = array(
    'class' => 'fusion-logo-link',
    'href' => $link,
  );

  return $link_arr;

}

//This is for page-2
add_filter('avada_logo_anchor_tag_attributes', 'broadway_logo_link_modify');
function broadway_logo_link_modify() {

  $link = esc_url( home_url( '/' ) );

  if (is_page( array (169))) {
    $link = 'https://sampleurl.com/page-2/';
  }

  // another option with which you don't have to add every page id
  $current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  if (strpos($current_url, 'https://sampleurl.com/page-2/') !== false) {
    $link = 'https://sampleurl.com/page-2/';
  }

  $link_arr = array(
    'class' => 'fusion-logo-link',
    'href' => $link,
  );

  return $link_arr;

}

I am trying to add the url for /page-2 and /page-3. I added the code again and change the URL to https://sampleurl.com/page-2/ but it broke the site "HTTP Error".

Anyone knows what's the right code to add? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doujian4752 2019-01-14 09:57
    关注

    Now you are using same function name for both function at that time same function name declaration will cause php error. For avoiding that problem you can rename the second function name like as following code.

    //This is for page-1
    add_filter('avada_logo_anchor_tag_attributes', 'broadway_logo_link_modify1');
    function broadway_logo_link_modify1() {
    
      $link = esc_url( home_url( '/' ) );
    
      if (is_page( array (169))) {
        $link = 'https://sampleurl.com/page-1/';
      }
    
      // another option with which you don't have to add every page id
      $current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
      if (strpos($current_url, 'https://sampleurl.com/page-1/') !== false) {
        $link = 'https://sampleurl.com/page-1/';
      }
    
      $link_arr = array(
        'class' => 'fusion-logo-link',
        'href' => $link,
      );
    
      return $link_arr;
    
    }
    
    //This is for page-2
    add_filter('avada_logo_anchor_tag_attributes', 'broadway_logo_link_modify2');
    function broadway_logo_link_modify2() {
    
      $link = esc_url( home_url( '/' ) );
    
      if (is_page( array (210))) {
        $link = 'https://sampleurl.com/page-2/';
      }
    
      // another option with which you don't have to add every page id
      $current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
      if (strpos($current_url, 'https://sampleurl.com/page-2/') !== false) {
        $link = 'https://sampleurl.com/page-2/';
      }
    
      $link_arr = array(
        'class' => 'fusion-logo-link',
        'href' => $link,
      );
    
      return $link_arr;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀