get_the_ID() is working on my local development but not on staging server

The problem is this part:

wp_get_attachment_image_src($image, 'large')[0]

In old PHP versions like 5.3 and below, you cannot reference an entry ([0]) from the returned array of a function. The problem is that WP Engine is still on PHP 5.3, which reached end of life recently and doesn’t get security updates anymore. For the history see PHP 5.3 – Thanks for all the Fish.

You have two options:

  1. Find all occurrences of modern syntax and rewrite them to make it compatible with 5.3. In this case:

    $img_data = wp_get_attachment_image_src($image, 'large');
    $src = $img_data[0];
    
  2. Switch to a newer PHP version, preferably 5.5. If your current hoster cannot do that find a better one.

Leave a Comment