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

时间:2018-06-08 18:14:15

标签: php html wordpress wordpress-theming customization

我正在尝试自定义Avada,以便在您访问某些网页时将主网站徽标链接到自定义网址。我将 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 文件中插入自定义网址?

1 个答案:

答案 0 :(得分:0)

您提供的代码仅与<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)中。