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;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站