【问题标题】:Wordpress - Custom HeaderWordpress - 自定义标题
【发布时间】:2015-05-07 10:05:42
【问题描述】:

我正在尝试为我的 wordpress 主题获取自定义标题。

    $args = array(
    'width'         => 1920,
    'height'        => 800,
    'default-image' => get_template_directory_uri() . '/images/header.jpg',
    'uploads'       => true,
); add_theme_support( 'custom-header', $args );

将其添加到我的functions.php中,并希望默认图像是在管理员中没有设置图像时显示的图像。

但它不会显示任何内容。 “img src”为空。

尝试上传图片然后显示,可能是什么问题?

<img src="<?php echo header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

在我的 front-page.php 中使用它(宽度和高度设置正确)。

【问题讨论】:

    标签: php html css wordpress wordpress-theming


    【解决方案1】:

    我没有发现您的代码有任何问题。但是,您可以在下面尝试。它对我来说总是很有效。

    <?php if (get_header_image()) { ?>
        <img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>">
    <?php } else { ?>
        <img src="<?php echo get_template_directory_uri(); ?>/images/header.jpg" alt="<?php bloginfo('name'); ?>">
    <?php } ?>
    

    【讨论】:

      【解决方案2】:

      试试:

      <img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
      

      【讨论】:

      • 只有代码的答案通常可以从一些解释中受益。
      • 虽然这个答案可能是正确且有用的,但最好在其中附上一些解释来解释它如何帮助解决问题。如果有更改(可能不相关)导致它停止工作并且用户需要了解它曾经是如何工作的,这在未来变得特别有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      相关资源
      最近更新 更多