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

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]

 

Leave a reply

0
Connecting
Please wait...
Send a message

Sorry, we aren't online at the moment. Leave a message.

Your name
* Email
* Describe your issue
Chat now

Need more help? Save time by starting your support request online.

Your name
* Email
* Describe your issue
We're online! Ask us anything!
Feedback

Help us help you better! Feel free to leave us any additional feedback.

How do you rate our support?