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

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

我尝试添加我在stackoverflow中找到的代码。 这在徽标链接指向页面“169”上正常工作 https://sampleurl.com/page-1/ 。</ p>

  //这是针对page-1 
add_filter('avada_logo_anchor_tag_attributes','broadway_logo_link_modify');

ntortway_logo_link_modify(){

$ link = esc_url(home_url('/'));

if(is_page(array(169))){
$ link ='https://sampleurl.com/page-1/';
}

//另一个选项,你不必添加每个页面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'=&gt;'fusion-logo-link',
'href'=&gt; $ link,
);

返回$ link_arr; \ n
}

//这是针对page-2
add_filter('avada_logo_anchor_tag_attributes','broadway_logo_link_modify');

unfunctionway_logo_link_modify(){

$ link = esc_url(home_ur l('/'));

if(is_page(array(169))){
$ link ='https://sampleurl.com/page-2/';
}

//另一个选项,你不必添加每个页面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/';
}
\ n $ link_arr = array(
'class'=&gt; 'fusion-logo-link',
'href'=&gt; $ link,
);

返回$ link_arr;

}
</ code> </ pre>

我正在尝试添加/ page-2和 /页-3。 我再次添加了代码并将URL更改为 https://sampleurl.com/page-2/但它打破了网站“HTTP错误”。</ p>

任何人都知道要添加的代码是什么? 提前致谢。</ p>
</ div>

展开原文

原文

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.

douchen4547
douchen4547 请更改第二个功能名称
一年多之前 回复

1个回答



现在你正在为这两个函数使用相同的函数名,同时函数名声明将导致php错误。 为避免该问题,您可以重命名第二个函数名称,如下面的代码。 </ p>

  //这是针对page-1 
add_filter('avada_logo_anchor_tag_attributes','broadway_logo_link_modify1');

functionway_logo_link_modify1(){

$ link = esc_url(home_url ('/'));

if(is_page(array(169))){
$ link ='https://sampleurl.com/page-1/';
}

/ /另一个选项,你不必添加每个页面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'=&gt;'fusion-logo-link',
'href'=&gt; $ link,
);

返回$ link_arr;

} \ n
//这适用于page-2
add_filter('avada_logo_anchor_tag_attributes','broadway_logo_link_modify2');

nfunction broadway_logo_link_modify2(){

$ link = esc_url(home_url('/'));

if(is_page(array(210))){
$ link ='https://sampleurl.com/page-2/';
}

//另一个你不需要的选项 添加每个页面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'= &GT; 'fusion-logo-link',
'href'=&gt; $ link,
);

返回$ link_arr;

}
</ code> </ pre>
</ div>

展开原文

原文

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;

}

dongpan2788
dongpan2788 复制我理解...感谢您的帮助
一年多之前 回复
douchen3562
douchen3562 您好,感谢您的反馈。 我更改了功能名称,第2页的链接工作正常,但对于第1页,它链接回主页...任何想法? 谢谢
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问