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

通过编辑Avada子主题logo.php在WordPress网站上切换特定页面的logo

我正在尝试使特定页面在页眉中使用不同的徽标。我从Avada主题复制了logo.php文件到我的子主题文件夹(Avada-Child-Theme / templates / logo.php)。

我补充说:

    if (is_page(array (194, 248)))
{
  $standard_logo = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
}

        if (is_page(array (194, 248)))
{
  $retina_logo = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
}

这是完整的新logo.php文件:

<?php
/**
 * Logo template.
 *
 * @author     ThemeFusion
 * @copyright  (c) Copyright by ThemeFusion
 * @link       http://theme-fusion.com
 * @package    Avada
 * @subpackage Core
 */

// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
    exit( 'Direct script access denied.' );
}
$logo_opening_markup = '<div class="';
$logo_closing_markup = '</div>';
if ( 'v7' === Avada()->settings->get( 'header_layout' ) && ! Avada()->settings->get( 'logo_background' ) ) {
    $logo_opening_markup = '<li class="fusion-middle-logo-menu-logo ';
    $logo_closing_markup = '</li>';
} elseif ( 'v7' === Avada()->settings->get( 'header_layout' ) && Avada()->settings->get( 'logo_background' ) && 'Top' === Avada()->settings->get( 'header_position' ) ) {
    $logo_opening_markup = '<li class="fusion-logo-background fusion-middle-logo-menu-logo"><div class="';
    $logo_closing_markup = '</div></li>';
} elseif ( Avada()->settings->get( 'logo_background' ) && 'v4' !== Avada()->settings->get( 'header_layout' ) && 'v5' !== Avada()->settings->get( 'header_layout' ) && 'Top' === Avada()->settings->get( 'header_position' ) ) {
    $logo_opening_markup = '<div class="fusion-logo-background"><div class="';
    $logo_closing_markup = '</div></div>';
}
?>
<?php if ( '' !== Avada()->settings->get( 'logo', 'url' ) || '' !== Avada()->settings->get( 'logo_retina', 'url' ) ) : ?>
    <?php echo $logo_opening_markup; // WPCS: XSS ok. ?>fusion-logo" data-margin-top="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'top' ) ); ?>" data-margin-bottom="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'bottom' ) ); ?>" data-margin-left="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'left' ) ); ?>" data-margin-right="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'right' ) ); ?>">
<?php else : ?>
    <?php echo $logo_opening_markup; // WPCS: XSS ok. ?>fusion-logo" data-margin-top="0px" data-margin-bottom="0px" data-margin-left="0px" data-margin-right="0px">
<?php endif; ?>
<?php
    /**
     * The avada_logo_prepend hook.
     */
    do_action( 'avada_logo_prepend' );

    $logo_anchor_tag_attributes = '';
    $logo_anchor_tag_attributes_array = apply_filters( 'avada_logo_anchor_tag_attributes', array(
            'class' => 'fusion-logo-link', 'href'  => ( $custom_link = Avada()->settings->get( 'logo_custom_link' ) ) ? esc_url( $custom_link ) : esc_url( home_url( '/' ) ), )
    );

    foreach ( $logo_anchor_tag_attributes_array as $attribute => $value ) {
        if ( 'href' === $attribute ) {
            $value = esc_url( $value );
        } else {
            $value = esc_attr( $value );
        }

        $logo_anchor_tag_attributes .= ' ' . $attribute . '="' . $value . '" ';
    }

        if (is_page(array (194, 248)))
    {
      $standard_logo = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
    }

            if (is_page(array (194, 248)))
    {
      $retina_logo = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
    }

    $logo_alt_attribute = apply_filters( 'avada_logo_alt_tag', get_bloginfo( 'name', 'display' ) . ' ' . __( 'Logo', 'Avada' ) );
    ?>
    <?php if ( ( Avada()->settings->get( 'logo', 'url' ) && '' !== Avada()->settings->get( 'logo', 'url' ) ) || ( Avada()->settings->get( 'logo_retina', 'url' ) && '' !== Avada()->settings->get( 'logo_retina', 'url' ) ) ) : ?>
        <a<?php echo $logo_anchor_tag_attributes; // WPCS: XSS ok. ?>>

            <?php $standard_logo = Avada()->images->get_logo_image_srcset( 'logo', 'logo_retina' ); ?>
            <!-- 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' );
            ?>
                <!-- 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 } ?>

            <?php
            if ( Avada()->settings->get( 'sticky_header_logo', 'url' ) && '' !== Avada()->settings->get( 'sticky_header_logo', 'url' ) && ( in_array( Avada()->settings->get( 'header_layout' ), array( 'v1', 'v2', 'v3', 'v6', 'v7' ) ) || ( ( in_array( Avada()->settings->get( 'header_layout' ), array( 'v4', 'v5' ) ) && 'menu_and_logo' === Avada()->settings->get( 'header_sticky_type2_layout' ) ) ) ) ) {
                $sticky_logo = Avada()->images->get_logo_image_srcset( 'sticky_header_logo', 'sticky_header_logo_retina' );
            ?>
                <!-- sticky header logo -->
                <img src="<?php echo esc_url_raw( $sticky_logo['url'] ); ?>" srcset="<?php echo esc_attr( $sticky_logo['srcset'] ); ?>" width="<?php echo esc_attr( $sticky_logo['width'] ); ?>" height="<?php echo esc_attr( $sticky_logo['height'] ); ?>"<?php echo $sticky_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $sticky_logo['is_retina'] ); ?>" class="fusion-sticky-logo" />
            <?php } ?>
        </a>
    <?php endif; ?>
    <?php
    /**
     * The avada_logo_append hook.
     *
     * @hooked avada_header_content_3 - 10.
     */
    do_action( 'avada_logo_append' );

    ?>
<?php
echo $logo_closing_markup; // WPCS: XSS ok.

/* Omit closing PHP tag to avoid "Headers already sent" issues. */

我试过了:

$standard_logo[‘url’] = ‘/wp-content/uploads/2018/05/broadway-binghamton-logo.png’;

也一样当前文件仅适用于指定的页面, 但是我在这些页面的顶部看到此错误:

警告:第73行的/www/wp-content/themes/Avada-Child-Theme/templates/logo.php中的字符串偏移量’url’不合法

我不知道如何使它工作。网站是http://nac.flywheelsites.com/, 要查看, 联合国:flywheel PW:ideakraft

在主导航栏中的”城市”下, 我正在尝试更改宾厄姆顿的徽标。

图片网址正确。

我会将其放置在PHP文件中的错误位置吗?我尝试了几个不同的地方。请指教。非常感谢。


#1


不要将其设置为字符串-你在数组的正确位置上。

我认为你必须同时设置” url”和” srcset”:

// fetch logo normally
$standard_logo = Avada()->images->get_logo_image_srcset( 'logo', 'logo_retina' ); 

// see what that logo structure is like so you know what to override
// echo "<pre>"; print_r($standard_logo); echo "</pre>";


// if on these pages, override the srcset and url
        if (is_page(array (194, 248)))
        {
          $standard_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
          $retina_logo['url'] = $retinal_logo['srcset'];
        } 

否则, 我不会立即看到任何问题。 。 。确保阵列中的ID是正确的。并确保在使用Avada函数正常提取徽标后放置IF条件, 否则Avada函数将覆盖新变量。


#2


答案是将每种徽标类型(标准, 移动等)的自定义徽标放置在图像源esc_url_raw()函数上方。

<?php $standard_logo = Avada()->images->get_logo_image_srcset( 'logo', 'logo_retina' ); ?>
        <!-- custom standard logos -->
        <?php
        //Binghamton
        if (is_page( 194 ))
        {
          $standard_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-binghamton-logo-retina.png';
          $retina_logo['url'] = $standard_logo['srcset']; 
        } 
        //Erie
        if (is_page( 248 ))
        {
          $standard_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-erie-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-erie-logo.png';
          $retina_logo['url'] = $standard_logo['srcset']; 
        } 
        //Scranton
        if (is_page( 250 ))
        {
          $standard_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-scranton-logo.png';
          $standard_logo['url'] = $standard_logo['srcset'];
          $retina_logo['srcset'] = 'http://nac.flywheelsites.com/wp-content/uploads/2018/05/broadway-scranton-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" />

页面条件运行良好, 通过回显进行了测试。刚需要在打印徽标图像之前执行自定义代码。

赞(0) 打赏
未经允许不得转载:srcmini » 通过编辑Avada子主题logo.php在WordPress网站上切换特定页面的logo
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

微信扫一扫打赏