如何使用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;

}

来源:

https://www.srcmini02.com/63169.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37676.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?