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 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?