February 25

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

0  comments

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]

 


Tags

get, how, index, rid, to, undefined, wordpress


You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

Name*
Email*
Message
0 of 350