Jump to content

Variable won't display


otester

Recommended Posts

My site works like this for each page using the php include() feature:

 

 

(include top half of site - top.php)

 

(page content, eg: page1.php page2.php etc.)

 

(include bottom of site - bottom.php)

 

 

I want to generate meta tags, so I tried (top half of site:

 

<meta name="keywords" content="<?php echo $keywords; ?>">

 

 

Each page has this:

 

<?php $keywords = "dog, cat, mouse"; ?>

 

 

When I check on my site it says (checking source code via browser):

 

<meta name="keywords" content=""> 

:shrug:

 

 

Any ideas on how to get it to display the keywords?

 

 

Thanks,

 

otester

Link to comment
https://forums.phpfreaks.com/topic/208885-variable-wont-display/
Share on other sites

The variable has to have a value before it can be used. By your description, you're doing this:

 

echo $keywords;

$keywords = "stuff, stuff, more stuff";

 

That won't work that way.

The variable has to have a value before it can be used. By your description, you're doing this:

 

echo $keywords;

$keywords = "stuff, stuff, more stuff";

 

That won't work that way.

 

Is there any way to do what I want to do?

Yes, it's done all the time. Set the variables before including the header and footer.

 

main.php

$title = 'Page Title';
$keywords = 'word1, word2, word3';

include('header.php');
[main body stuff]
include('footer.php');

Yes, it's done all the time. Set the variables before including the header and footer.

 

main.php

$title = 'Page Title';
$keywords = 'word1, word2, word3';

include('header.php');
[main body stuff]
include('footer.php');

 

So simple, I should have seen it, works now. Thanks dude!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.