I've been working on a wordpress project for the past few days on my localhost. When I was done with it, I tried uploading it on my live host. But when the installation was finished, it showed a syntax error, saying "Parse error: syntax error, unexpected '[' in ..."
The code is the following :
function Consulin_header_style() {
if (Consulin_meta('enable_custom_header_style') == 1):
$images = Consulin_decode(Consulin_meta( 'header_image'));
$header_images = '.page-title { background-image: url('. wp_get_attachment_image_src($images[0],'flat-page-title')[0].');}';
else:
if ( get_header_image() != "" ) {
$header_images = '.page-title { background-image: url('. get_header_image().');}';
} else {
$header_images = '.page-title { background-image: url('.CONSULIN_LINK.'images/page-title.jpg) ; }';
}
endif;
wp_add_inline_style( 'Consulin-style', $header_images );
}
The 4th line of the code which says "$header_images = ..." is the problem. I have absolute zero knowledge of programming, so I'd appreciate some help here.
P.S: It works perfectly fine on localhost.
As the comment states, this error is related to php versions. You have an older php version in your production environment. Still, to make your code backwards compatible, you could change your code to something like this:
// …
if (Consulin_meta('enable_custom_header_style') == 1):
$images = Consulin_decode(Consulin_meta( 'header_image'));
$imageData = wp_get_attachment_image_src($images[0],'flat-page-title');
$header_images = '.page-title { background-image: url('. $imageData[0].');}';
else:
// …
Explanation:
In older versions of php you could not use the return value of a function directly. The solution above stores the return value in a temporary variable, and using that when referencing its [0]
index.