«

»

06 2016

Fix unexpected ‘[‘ error of XML Sitemap & Google News feeds

Fix unexpected ‘[’ error of XML Sitemap & Google News feeds

If you upgrade your XML Sitemap & Google News feeds to version 4.7, your wordpress may get a error message:

Parse error: syntax error, unexpected '[' in ...wp-content\plugins\xml-sitemap-feed\includes\class-xmlsitemapfeed.php on line 703....

If you don’t want to wait a newer version to fix this error, and don’t want to downgrade this plugin, you can fix this error by yourself.

If you are in a hurry, go the end of this article, and read the section How to fix it.

The problem

After upgrading the plugin XML Sitemap & Google News feeds to version 4.7, you will find this plugin is off. Try turn it on, and fail with a error message like:

Parse error: syntax error, unexpected '[' in ...wp-content\plugins\xml-sitemap-feed\includes\class-xmlsitemapfeed.php on line 703....

The reason

Let’s review the code near the line 703:

The key is line 703, $allowed = ['zh-cn','zh-tw'];. If you know PHP, what do you think, now?

Nothing weird.

Yes, Nothing weird there. This line creates a array, just clean, clear and simple.

The real problem is not the code, but the environment of your server.

Refer to this article Arrays, see this:

You should know that you can’t create a array with ‘[]’ until you running PHP 5.4 or higher.
If your PHP is 5.3 or lower, you will get error.

In the WordPress minimum requirements, it tells that WordPress also works with PHP 5.2.4+ ,so you can run wordpress on a low version of PHP, but not all plugins.

How to fix it

Just know your server’s PHP version may be 5.2 or 5.3. Let’s just create a array with a traditional way:

Edit the line 703.
Before:

After:

Fixed!

1 comment

  1. 夏天烤洋芋

    不是很懂这说的是什么?

发表评论

电子邮件地址不会被公开。 必填项已用*标注