Remove Illegal String Offset warning on WordPress sites

Remove Illegal String Offset warning on WordPress sites

The “Illegal string offset” warning error occurs when the function is being passed as a string instead of an array. The problem lies elsewhere, with the caller of the code not providing a correct parameter.

If you are good in PHP, you can offset this error by replacing the line being referred in the warning notification by:

if (is_array($inputs) && $inputs[‘type’] == ‘attach’) {

The warning message is new to PHP newer versions. Old versions didn’t warn if this happened. They would silently convert ‘type’ to 0, then try to get character 0 (the first character) of the string. I got the same error while working for a clients website, in my case the PHP version of the site was 7.1.6 – I  just reverted back to PHP version 7.0.20 and the error disappeared.

Most of the themes haven’t actually updated to latest PHP. If you don’t want to update your theme now, you can revert back to PHP version, and this will remove warnings from your website.

About the Author