Link 自定义 URL 的主徽标而不是主页,带有 WordPress Avada 子主题?

Link main logo to custom URLs instead of homepage, with WordPress Avada child theme?

我正在尝试将 Avada 自定义为 link 主站点徽标,以便在您访问某些页面时自定义 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 } ?>

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

http://nac.flywheelsites.com/broadway-in-binghamton/ displays the Binghamton logo but links back to http://nac.flywheelsites.com/ 当前。

我试过了:

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

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

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

Avada 是一个巨大的主题,可能有一个针对徽标的过滤器 link,您可以使用它来更改它。我用Avada的不多,建议你问问他们。


更新,找到正确的 Avada 徽标后 link 过滤器 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)。