Fatal error: Cannot redeclare get_header_image() (previously declared in

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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?

Share Improve this question asked Jun 20, 2019 at 6:59 Murat DenizMurat Deniz 77 bronze badges 2
  • 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 Commented Jun 20, 2019 at 7:04
  • @ParthaviPatel in fact i try to enable header image option of theme so what must i do ? – Murat Deniz Commented Jun 20, 2019 at 7:08
Add a comment  | 

1 Answer 1

Reset to default 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).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745385362a4625415.html

相关推荐

  • Fatal error: Cannot redeclare get_header_image() (previously declared in

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信