-2

I'm new to coding and I'm not really sure how to rewrite this line without the [].

Parse error: syntax error, unexpected '[' in header.php on line 18

<img 
    style="margin-top: 9px;" 
    alt="" 
    src="<?php echo (wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' ))[0]; ?>" 
    width="<?php echo get_custom_header()->width; ?>" 
    height="<?php echo get_custom_header()->height; ?>"
>

Any help would be appreciated.

Nuri Tasdemir
  • 9,720
  • 3
  • 42
  • 67

2 Answers2

1

"Note: The echo() function is not actually a function, so you are not required to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error." taken by: W3C php echo page

The parse error occurs because the parenthesis after echo closes the echo, you're writing something like that:

php echo (....)[0];

Which is wrong, maybe you need to add parenthesis:

echo ((wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' ))[0]);

In order to write

echo (....[0]);
Maurizio Ricci
  • 462
  • 1
  • 4
  • 11
0

What most likely causes the error is that you are using an old PHP version.

Array dereferencing from function return values was introduced in PHP 5.4:

// on PHP 5.4
$secondElement = getArray()[1];

Previously you had to do it in this way:

// previously
$tmp = getArray();
$secondElement = $tmp[1];
Marco
  • 7,007
  • 2
  • 19
  • 49