• Hi everybody.
    I’ve changed functions.php with following lines:

    //======================
    // get current theme name
    $theme_name = get_current_theme();

    // header image themes default folder
    define( ‘HEADER_IMAGE’, ‘%s/images/header.jpg’ );

    // get header image size (width, height)
    list($width, $height) = getimagesize(‘../wp-content/themes/’ . $theme_name . ‘/images/header.jpg’);

    // read width of header image
    define( ‘HEADER_IMAGE_WIDTH’, apply_filters( ”, $width ) );
    // read height of header image
    define( ‘HEADER_IMAGE_HEIGHT’, apply_filters( ”, $height ) );
    define( ‘NO_HEADER_TEXT’, true );

    // enable Dashboard Appearance > Header
    add_custom_image_header( ”, ‘admin_header_style’ );

    // Code is for Styling the Admin Side
    if ( ! function_exists( ‘admin_header_style’ ) ) :
    function admin_header_style() {
    ?>
    <style type=”text/css”>
    #heading {
    height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
    }
    #heading h1, #heading #desc {
    display: none;
    }
    </style>
    <?php
    }
    endif;

    //======================

    When I launch the dashboard Appearence –> Header to change header image, the function getimagesize() works fine and the image dimensions are ok.
    (You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.
    Images of exactly 874 × 200 pixels will be used as-is.)
    ————-
    But, when I launch the site I receive this error message:

    Warning: getimagesize(../wp-content/themes/winter/images/header.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\htdocs\blognoster\wp-content\themes\winter\functions.php on line NNN

    where NNN is the line:
    list($width, $height) = getimagesize(‘../wp-content/themes/’ . $theme_name . ‘/images/header.jpg’); // get header image
    ————
    Needs an helps.
    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • does this file exist on your computer?

    C:\xampp\htdocs\blognoster\wp-content\themes\winter\images\header.jpg

    If not, that is what the error message is about, no such file.

    Thread Starter Stefano

    (@stizzy)

    Thanks for your replay.
    some changes:

    $style_dir = get_stylesheet_directory() ;
    list($width, $height, $type, $attr) = getimagesize($style_dir . ‘/images/header.jpg’);

    and it works.

    Now, the problem move to other side:
    when I go to Appearence –> Header to change header image by browsing on my local disk and than –> ‘Upload’, the uploaded image stay in wp-content/uploads/2011/01/cropped-autumn4.jpg

    Launching the browser the uploaded image is not present…uffa !

    Suggestions ??

    Do you have Firebug installed in Firefox? If not I suggest you do so.

    If you do, check the URL of the image the browser is trying to load. Ten to one the file is not found at the location the browser is looking for it at.

    Thread Starter Stefano

    (@stizzy)

    The image url is correct:
    http://localhost/blognoster/0/wp-content/uploads/2011/01/cropped-fractals1.jpg
    Launching the browser I see the image.

    The problem is that css”force” header image, maybe:

    background-image: url(“images/header.jpg”);

    The image url is correct:
    http://localhost/blognoster/0/wp-content/uploads/2011/01/cropped-fractals1.jpg
    Launching the browser I see the image.

    The problem is that css”force” header image, maybe:

    background-image: url(“images/header.jpg”);

    What is the problem you are having? I am not clear on what is wrong.

    Thread Starter Stefano

    (@stizzy)

    thanks for your patience.
    The problem is that new uploaded header image (cropped-autumn4.jpg) go to in the folder wp-content/uploads/2011/01/
    but css search background-image: url(“images/header.jpg”);
    I cannot dinamically change the css, maybe…..

    There are two possible places that display the wrong image

    functions.php

    // header image themes default folder
    define( 'HEADER_IMAGE', '%s/images/header.jpg' );

    css

    background-image: url("images/header.jpg");

    change those to the image you want displayed and see if that resolves the problem.

    Thread Starter Stefano

    (@stizzy)

    If you follow the code from the Twenty Ten theme it will work correctly. It would be better if you install your images as part of the default header images array in functions.php and then select it on the headers option under Appearances in the Dashboard Nav.

    You can leave them in the Uploads folder if you want to. Just make sure the array in functions.php is set to find the images where they really are if they are not in the stylesheet folder.

    There are some tutorials on this you can find searching Google. I’ve used it on several sites. Once I figured out how it worked it works well and pretty easily.

    Thread Starter Stefano

    (@stizzy)

    Hi, and thanks again for your patience.
    After a ‘mumble-mumble’ night, finally I solved the problem.

    Lines to insert in function.php:
    //========== START ========================

    //Custom Header & Background
    add_custom_background();
    // get current theme folder
    $style_dir = get_stylesheet_directory() ;
    // get header image size
    list($width, $height, $type, $attr) = getimagesize($style_dir . ‘/images/header.jpg’);
    //define( ‘NO_HEADER_TEXT’, true );
    define(‘HEADER_TEXTCOLOR’, ‘fff’);
    define(‘HEADER_IMAGE’, ‘%s/images/header.jpg’);
    define(‘HEADER_IMAGE_WIDTH’, $width ) ; // read width of header image
    define(‘HEADER_IMAGE_HEIGHT’, $height ) ; // read height of header image

    // function for corrected WP site visualization
    function header_style() {
    ?>
    <style type=”text/css”>
    YOUR CSS DIV CONTAINING HEADER IMAGE {
    background: url(<?php header_image() ?>);
    height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
    }

    YOUR CSS HEADER TITLE{
    }
    YOUR CSS HEADER SUBTITLE {
    }
    <?php
    if ( ‘blank’ == get_header_textcolor() ) { ?>
    YOUR CSS HEADER TITLE, YOUR CSS DIV CONTAINING HEADER IMAGE YOUR CSS HEADER SUBTITLE {
    display: none;
    }
    <?php } else {
    ?>
    YOUR CSS HEADER TITLE a, YOUR CSS HEADER SUBTITLE {
    color:#<?php header_textcolor() ?>;
    }
    <?php } ?>
    </style>
    <?php
    }

    // function for corrected WP Dashboard visualization
    function admin_header_style() {
    ?>
    <style type=”text/css”>
    #headimg{
    background: url(<?php header_image() ?>) no-repeat;
    height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
    padding:0 0 0 18px;
    font-family: arial;
    }
    #headimg h1{
    padding-top:20px;
    margin: 0;
    }
    #headimg h1 a, #desc{
    color:#<?php header_textcolor() ?>;
    text-decoration: none;
    border-bottom: none;
    }
    #desc {
    padding-top: 15px;
    }
    <?php if ( ‘blank’ == get_header_textcolor() ) { ?>
    #headimg h1, #headimg #desc {
    display: none;
    }
    #headimg h1 a, #headimg #desc {
    color:#<?php echo HEADER_TEXTCOLOR ?>;
    }
    <?php } ?>
    </style>
    <?php
    }
    add_custom_image_header(‘header_style’, ‘admin_header_style’);

    //========== END =====================

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Read Custom Header Image Size’ is closed to new replies.