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

使用WordPress Avada子主题将主logo链接到自定义URL而不是首页?

当你在某些页面上时, 我正在尝试自定义Avada以将主站点徽标链接到自定义URL。我将logo.php复制到子主题中并添加了以下内容:

        <?php $standard_logo = Avada()->images->get_logo_image_srcset( 'logo', 'logo_retina' ); ?>
        <!-- custom standard logos -->
        <?php
        //Binghamton
        if (is_page( array (194, 376, 534, 329, 499, 489, 479, 476, 467)))
        {
          $standard_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-binghamton-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-binghamton-logo-retina.png';
          $retina_logo['url'] = $standard_logo['srcset'];
        }

        //Erie
        if (is_page( array (248, 382, 589, 926, 1542, 1537, 1514)))
        {
          $standard_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-erie-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-erie-logo.png';
          $retina_logo['url'] = $standard_logo['srcset'];
        }
        ?>
        <!-- standard logo -->
        <img src="<?php echo esc_url_raw( $standard_logo['url'] ); ?>" srcset="<?php echo esc_attr( $standard_logo['srcset'] ); ?>" width="<?php echo esc_attr( $standard_logo['width'] ); ?>" height="<?php echo esc_attr( $standard_logo['height'] ); ?>"<?php echo $standard_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $standard_logo['is_retina'] ); ?>" class="fusion-standard-logo" />

        <?php
        if ( Avada()->settings->get( 'mobile_logo', 'url' ) && '' !== Avada()->settings->get( 'mobile_logo', 'url' ) ) {
            $mobile_logo = Avada()->images->get_logo_image_srcset( 'mobile_logo', 'mobile_logo_retina' );
        ?>
            <!-- custom mobile logos -->
            <?php
            //Binghamton
            if (is_page( array (194, 376, 534, 329, 499, 489, 479, 476, 467)))
            {
              $mobile_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-binghamton-logo.png';
              $mobile_logo['url'] = $mobile_logo['srcset'];
            }

            //Erie
            if (is_page( array (248, 382, 589, 926, 1542, 1537, 1514)))
            {
              $mobile_logo['srcset'] = '/wp-content/uploads/2018/06/broadway-erie-logo.png';
              $mobile_logo['url'] = $mobile_logo['srcset'];
            }
            ?>
            <!-- mobile logo -->
            <img src="<?php echo esc_url_raw( $mobile_logo['url'] ); ?>" srcset="<?php echo esc_attr( $mobile_logo['srcset'] ); ?>" width="<?php echo esc_attr( $mobile_logo['width'] ); ?>" height="<?php echo esc_attr( $mobile_logo['height'] ); ?>"<?php echo $mobile_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $mobile_logo['is_retina'] ); ?>" class="fusion-mobile-logo" />
        <?php } ?>

可以更改徽标以匹配正确的城市, 但是我需要将城市徽标链接到城市页面, 而不是首页。

http://nac.flywheelsites.com/broadway-in-binghamton/显示Binghamton徽标, 但当前链接回http://nac.flywheelsites.com/。

我试过了:

$standard_logo['/broadway-in-binghamton/'] = $standard_logo['srcset'];

但我认为那是不对的。类似的问题说要进入header.php文件并找到你的徽标类, 但是此主题不会将其存储在那里。有没有办法在logo.php文件中插入自定义URL?


#1


你提供的代码仅与<img>有关。当我检查你的网站时, 我看到两个徽标(正常和视网膜)都包裹在链接中:<a class=”fusion-logo-link” href=”http://nac.flywheelsites.com/”>。你需要找到该链接的来源(可能是header.php)。

OR

Avada是一个巨大的主题, 可能有一个徽标链接过滤器可用于更改它。我不太会使用Avada, 建议你问他们。


找到正确的Avada徽标链接过滤器后进行更新avada_logo_anchor_tag_attributes

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 (248, 382, 589, 926, 1542, 1537, 1514))) {
    $link = 'http://nac.flywheelsites.com/broadway-in-binghamton/';
  }

  // 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, 'http://nac.flywheelsites.com/broadway-in-binghamton/') !== false) {
    $link = 'http://nac.flywheelsites.com/broadway-in-binghamton/';
  }

  $link_arr = array(
    'class' => 'fusion-logo-link', 'href' => $link, );

  return $link_arr;

}

当然, 你必须扩展代码片段以适合你的需求, 但是你会明白的。将其放在你的functions.php(不是logo.php)中。

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

评论 抢沙发

评论前必须登录!