Skip to content Skip to sidebar Skip to footer

How to get rid of undefined index warning in wordpress themes?

As a wordpress theme developer, when you are working with WP_DEBUG on, you are most likely to get the following notice: “Notice: Undefined index….some_variable“.

This warning is caused by the fact that the variable is empty or unset when the wordpress theme is activated or at some other point.

You can solve this warning pretty quick with just few lines of code. Let’s assume the variable we are getting the error for it’s called $some_variable. Here it’s how you do it.

[php]

<?php

if  (!empty($some_variable)){

//your output of the variable e.g. echo $some_variable;

}

?>

[/php]

 

What's your reaction?
0Smile0Lol0Wow0Love0Sad0Angry

Leave a comment