繁体   English   中英

嵌入header_image()中的Wordpress site_url返回值

[英]Wordpress site_url embedded in header_image() return value

我正在开发wordpress主题,目前正在为该主题实现自定义标题功能。 最初,我没有对主题应用自定义标题图像的问题,但突然header_image()开始返回一个值,例如: http://site_url/wp-content/themes/themename/img/headerimage.png

似乎site_url()函数没有被执行,而是嵌入在header_image()的返回值中。 但是当单独使用site_url()时,它将返回正确的值。

// header.php中用于显示图像的代码

<?php $header_image = get_header_image();
if ( ! empty( $header_image ) ) { ?>
     <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
       <img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
     </a>
<?php }
?>

// custom-header.php中的代码以设置自定义标头

function sens_gamer_custom_header_setup() {
    $args = array(
        'default-image'          => get_template_directory_uri() . '/img/sensationalgamerlogo1.png',
        'width'                  => 221,
        'height'                 => 90,
        'header-text'            => false,
        'wp-head-callback'       => 'sens_gamer_header_style',
        'admin-head-callback'    => 'sens_gamer_admin_header_style',
        'admin-preview-callback' => 'sens_gamer_admin_header_image',
        'uploads'                => true,
    );

    $args = apply_filters( 'sens_gamer_custom_header_args', $args );

    if ( function_exists( 'wp_get_theme' ) ) {
        add_theme_support( 'custom-header', $args );
    } else {
        // Compat: Versions of WordPress prior to 3.4.
        define( 'HEADER_IMAGE',        $args['default-image'] );
        define( 'HEADER_IMAGE_WIDTH',  $args['width'] );
        define( 'HEADER_IMAGE_HEIGHT', $args['height'] );
        add_custom_image_header( $args['wp-head-callback'], $args['admin-head-callback'], $args['admin-preview-callback'] );
    }
}
add_action( 'after_setup_theme', 'sens_gamer_custom_header_setup' );


if ( ! function_exists( 'get_custom_header' ) ) {
    function get_custom_header() {
        return (object) array(
            'url'           => get_header_image(),
            'thumbnail_url' => get_header_image(),
            'width'         => HEADER_IMAGE_WIDTH,
            'height'        => HEADER_IMAGE_HEIGHT,
        );
    }
}


if ( ! function_exists( 'sens_gamer_header_style' ) ) :

function sens_gamer_header_style() {

    // If no custom options for text are set, let's bail
    // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
    if ( HEADER_TEXTCOLOR == get_header_textcolor() && '' == get_header_image() )
        return;
    // If we get this far, we have custom styles. Let's do this.
    ?>
    <style type="text/css">
    </style>
    <?php
}
endif; // sens_gamer_header_style

我也有同样的问题。 我没有解决方案,但是此解决方法对我有用:

<img src="<?php echo( str_replace('http://site_url', site_url(), get_header_image()) ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM