0

to use that code <img src="<?php echo esc_url( get_header_image() ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'title' ) ) ); ?>" /> , i created a functions.php like that

 <?php 

function get_header_image() { 
    $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); 

    if ( 'remove-header' == $url ) { 
        return false; 
    } 

    if ( is_random_header_image() ) { 
        $url = get_random_header_image(); 
    } 
} 
    ?>

but it shows error :

Fatal error: Cannot redeclare get_header_image() (previously declared in C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\wordpress\wp-includes\theme.php:1058) in C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\wordpress\wp-content\themes\html5blank-stable1\html5blank-stable\functions.php on line 13

so how can i solve it?

  • that means function with this name get_header_image is already declared in this file \wp-includes\theme.php change your function name to something eles like get_header_image_custom in functions.php file – Parthavi Patel Jun 20 '19 at 7:04
  • @ParthaviPatel in fact i try to enable header image option of theme so what must i do ? – Murat Deniz Jun 20 '19 at 7:08
1

The error message is pretty clear in this case.

You can’t have two functions with the same name.

WordPress already has function called get_header_image, so you can’t call your custom function with this name.

That’s why it’s a good idea to add prefixes to functions you declare in your theme. So instead get_header_image you call your custom function MYTHEME_get_header_image (of course replace MYTHEME with name of your theme).

| improve this answer | |
  • in fact i try to enable header image option of theme so what must i do ? – Murat Deniz Jun 20 '19 at 7:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.