简体   繁体   中英

Wordpress site_url embedded in header_image() return value

I am developing a wordpress theme and am currently working on implementing a custom header functionality for the theme. Initially, I had no issue with applying a custom header image to the theme, but all of a sudden the header_image() started returning a value such as: http://site_url/wp-content/themes/themename/img/headerimage.png

It seems that the site_url() function is not being executed and is embedded in the return value for header_image() . But when site_url() is used separately, it returns the correct value.

// Code in header.php for displaying image

<?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 }
?>

// Code in custom-header.php for setting up custom header

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

I have the same problem. I don't have a solution but this workaround works for me:

<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="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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