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

报告相同问题?