Undefined Index with WordPress theme options panel-Collection of common programming errors

In general I will inspect an array element before using it if it’s possible that it might not exist. (Which is essentially what the “undefined index” error is). There’s a shorthand if statement that tends to be convenient:


David Walsh has a nice tutorial that explains this syntax.

Another case… If your entire array might be empty and attempting to loop the array causes this error, wrap your loop in the following pattern:


Hope that helps. Have fun!

Originally posted 2013-11-09 21:07:19.