PHP error undefined variable notice how to fix?


can somebody make sense of this? This code leaves an irritating "undefined variable" php Notice on my page. First I have this in my header in Wordpress. (BTW, I'm picking up another dev's code)

$head .= "
<link rel='profile' href='' />
<link rel='stylesheet' type='text/css' media='all' href='".get_bloginfo( 'stylesheet_url' )."' />
<link rel='pingback' href='".get_bloginfo( 'pingback_url' )."' />

$head .= ob_get_clean();

Then this line of code is included in a separate file. <?=$head;?> <--- What's this?

Removing this last line actually breaks parts of wordpress. I'm happy to leave it in but how do I remove the error Notice?

And what's happening in this code here? When I try to declare the $head variable like this:

$head = null; 

It breaks everything.. I'm stumped. I know I need to leave it in. But I can't declare it. So php keeps up that notice. Ideas? Thanks.


Just remove the .= so that it is assigning a value to the $html rather than appending to it. You cannot append null to a string, which is why your second attempt failed. You could initialize it to an empty string, but it's an unnecessary extra step.

$head = "
<link rel='profile' href='' />
<link rel='stylesheet' type='text/css' media='all' href='".get_bloginfo( 'stylesheet_url' )."' />
<link rel='pingback' href='".get_bloginfo( 'pingback_url' )."' />

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at


Login to comment


"Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP

Notice: Undefined variable - WordPress / Parse Server Plugin - PHP Error

undefined index error in php and How to fix it

Notice: Undefined variable: id in PHP

Not able to fix "PHP Notice: Undefined variable" and "Undefined index" in code

How to fix the error undefined variable "$labels"in Prometheus?

PHP Notice: Undefined variable

Fix PHP Notice: 'Undefined index' on Wordpress

Notice: Undefined variable with <?= $property

PHP MySql - Notice: Undefined variable Error

how to Fix undefined variable?

PHP Notice: Undefined index and Form Fields error

PHP Notice: undefined variable, but they are already defined

php warning session variable, Notice: Undefined index:

Notice: Undefined variable in function +=

Notice: Undefined index: variable

Notice: Undefined variable: table

PHP Notice: Undefined variable:

PHP error: Notice: Undefined offset

How to fix Undefined offset-Error in PHP

Receiving Error: Notice: Undefined variable – but already defined

Getting error PHP Notice: Undefined variable: do_not_compress in my php code

Notice: Undefined variable: num

A PHP Error was encountered Severity: Notice Message: Undefined variable: result

How to fix "undefined index" notice elegantly?

how fix this error "Undefined variable: products (0)"

Notice: Undefined variable: grandTotal in PHP 7.1

I am facing an Undefined Variable:Notice Error in PHP

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP