Title: Echoing image dimensions
Last modified: September 1, 2016

---

# Echoing image dimensions

 *  Resolved [fabianborg](https://wordpress.org/support/users/fabianborg/)
 * (@fabianborg)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/)
 * Hi, I am trying to echo the image dimensions of a custom logo in my header.php.
   This is my code so far
 * **functions.php**
 *     ```
       function mytheme_customize_register( $wp_customize ) {
       $wp_customize->add_section( 'custom_logo_section' , array(
       'title'         => __( 'Logo', 'custom' ),
       'priority'      => 30,
       'description'   => 'Upload a logo to replace the default site name and description in the header',
       ));
       $wp_customize->add_setting( 'custom_logo' );
       $wp_customize->add_control( new WP_Customize_Image_Control(
       $wp_customize, 'custom_logo', array(
       'label'     => __( 'Logo', 'custom' ),
       'section'   => 'custom_logo_section',
       'settings'  => 'custom_logo',
       )
       ));
       }
       ```
   
 * **header.php**
 *     ```
       <?php if( get_theme_mod( 'custom_logo') ) : ?>
       <a href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> 'rel='home' class="navbar-brand"><img src='<?php echo esc_url( get_theme_mod( 'custom_logo' ) ); ?> 'width='<?php echo $width; ?>' 'height='<?php echo $height; ?>' 'alt='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>'></a></div>
       ```
   
 * The width and height integers are not displaying the image width and height dimensions.
   How can I solve this?

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

 *  [bravokeyl](https://wordpress.org/support/users/bravokeyl/)
 * (@bravokeyl)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583854)
 * Hi [@fabianborg](https://wordpress.org/support/users/fabianborg/),
 * Did you define `$width` and `$height` variables anywhere in `header.php` ?
    Can
   you also please post the entire code(like the initialization of those two variables).
 *  [bravokeyl](https://wordpress.org/support/users/bravokeyl/)
 * (@bravokeyl)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583855)
 *  Thread Starter [fabianborg](https://wordpress.org/support/users/fabianborg/)
 * (@fabianborg)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583856)
 * Hi @bravokey, no I did not define the variables in the header.php and neither
   in the functions.php were the custom_logo is created as I thought that the image
   properties would be transposed automatically.
 * As far as the code goes, I have posted all the relevant code.
 * What would be your suggestion, please?
 *  [bravokeyl](https://wordpress.org/support/users/bravokeyl/)
 * (@bravokeyl)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583858)
 * As far as I know those variables are not defined and they are available when 
   you are trying to echo.
 * You can try the following code which uses PHP `getimagesize` function.
 *     ```
       <?php if ( get_theme_mod( 'custom_logo' ) ) :
           $logo = get_theme_mod( 'custom_logo' );
           $logo_size = getimagesize($logo);
           $width = $logo_size[0];
           $height = $logo_size[1];
       ?>
       <a href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> 'rel='home' class="navbar-brand"><img src='<?php echo esc_url( get_theme_mod( 'custom_logo' ) ); ?> 'width='<?php echo $width; ?>' 'height='<?php echo $height; ?>' 'alt='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>'></a></div>
       ```
   
 * Taken from [WPSE](http://wordpress.stackexchange.com/a/215161/43098)
 *  Thread Starter [fabianborg](https://wordpress.org/support/users/fabianborg/)
 * (@fabianborg)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583924)
 * @bravokey
 * The solution provided worked out of the box. Thanks for that, I was overcomplicating
   things with `get_image_tag()` to make use of the string `$size` as myslef being
   new to wordpress I was not aware if wordpress supported `getimagesize`.
 * Once again thanks for the help 😉

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

The topic ‘Echoing image dimensions’ is closed to new replies.

## Tags

 * [images](https://wordpress.org/support/topic-tag/images/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [fabianborg](https://wordpress.org/support/users/fabianborg/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/echoing-image-dimensions/#post-7583924)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
