个性化阅读
专注于IT技术分析

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

我正在尝试更改特定页面的徽标链接, 以便它将链接到特定页面的自定义URL。

我试图添加我也在stackoverflow中找到的这段代码。在页面” 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;

}

我正在尝试为/ page-2和/ page-3添加URL。我再次添加了代码, 并将URL更改为https://sampleurl.com/page-2/, 但它破坏了站点” HTTP错误”。

任何人都知道要添加什么正确的代码吗?提前致谢。


#1


现在, 你同时在两个函数上使用相同的函数名称, 因此相同的函数名称声明将导致php错误。为避免该问题, 你可以像下面的代码一样重命名第二个函数名称。

//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;

}
赞(0)
未经允许不得转载:srcmini » 如何使用WordPress Avada子主题将主logo的链接更改为自定义URL而不是首页?

评论 抢沙发

评论前必须登录!