简体   繁体   English

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

[英]How to change link of main logo to custom URLs instead of homepage, with WordPress Avada child theme?

I am trying to change the logo link for specific pages, so that it will link to a custom URL for specific page. 我正在尝试更改特定页面的徽标链接,以便它将链接到特定页面的自定义URL。

I tried to add this code that I found also here in stackoverflow. 我试图添加我也在stackoverflow中找到的这段代码。 This works fine on page "169" the logo link point to https://sampleurl.com/page-1/ . 在页面“ 169”上,徽标链接指向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. 我正在尝试为/ page-2和/ page-3添加网址。 I added the code again and change the URL to https://sampleurl.com/page-2/ but it broke the site "HTTP Error". 我再次添加了代码,并将URL更改为https://sampleurl.com/page-2/,但它破坏了站点“ HTTP错误”。

Anyone knows what's the right code to add? 任何人都知道要添加什么正确的代码吗? Thanks in advance. 提前致谢。

Now you are using same function name for both function at that time same function name declaration will cause php error. 现在,您同时在两个函数上使用相同的函数名称,因此相同的函数名称声明将导致php错误。 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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM