php - 使用 WordPress Avada 子主题将主徽标链接到自定义 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?
解决方案
您提供的代码仅关于<img>
. 当我检查您的网站时,我看到两个徽标(正常和视网膜)都包含在一个链接中:<a class="fusion-logo-link" href="http://nac.flywheelsites.com/">
. 您需要找到该链接的来源(可能是 header.php)。
或者
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)中。
推荐阅读
- android - 在另一个 RelativeLayout 中膨胀 RelativeLayout
- python - psycopg2 - 将行插入多个表的最快方法?
- javascript - ERROR NgFor 仅支持绑定到 Iterables,例如 Arrays。JSON 数组有效
- php - 在服务器上上传和处理 txt 和 csv 文件的问题
- php - 如何使所有数据库更改遵循 UTC 时区?
- java - SSLException:无法识别的 SSL 消息,明文连接?通过代理在 Camel 中发送 https POST 时出错
- matlab - MATLAB:求解一系列方程以系统地调整概率估计
- sql - SQL 数据修复 INSERT 从多个具有相同 ID 的行中检索数据
- excel - 如果 Outlook 主题和收到日期
- git - SVN 到 Git 迁移:在 gitlab 中发现的其他提交