1

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='http://gmpg.org/xfn/11' />
<link rel='stylesheet' type='text/css' media='all' href='".get_bloginfo( 'stylesheet_url' )."' />
<link rel='pingback' href='".get_bloginfo( 'pingback_url' )."' />
";

ob_start();
wp_head();
$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.

6
  • where is this line of code?? <?=$head;?>; Commented Nov 14, 2015 at 5:57
  • @NiranjanNRaju It's included in the same file... Commented Nov 14, 2015 at 5:57
  • can you add the complete code?? i mean where you are echoing the $head. Commented Nov 14, 2015 at 6:00
  • @NiranjanNRaju it's all in the head on this site. All of this is in the header.php file. Does that help? on this site safestoragedepot.com/blog Commented Nov 14, 2015 at 6:02
  • Your dev is a terrible dev that doesn't conform to the Wordpress php coding standards Commented Nov 14, 2015 at 6:29

1 Answer 1

2

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='http://gmpg.org/xfn/11' />
<link rel='stylesheet' type='text/css' media='all' href='".get_bloginfo( 'stylesheet_url' )."' />
<link rel='pingback' href='".get_bloginfo( 'pingback_url' )."' />
";
Sign up to request clarification or add additional context in comments.

1 Comment

So the site is split up into two main areas. PHP and (Wordpress Env) the Blog. I ended up assigning the html to a new variable $html, replacing $head with $html in the wp header. Oddly enough I ended up deleting $head from the php header and now everything is fine. No more Notices and Wordpress is happy too. Thanks everyone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.