otester Posted July 26, 2010 Share Posted July 26, 2010 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=""> 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 More sharing options...
Pikachu2000 Posted July 26, 2010 Share Posted July 26, 2010 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. Link to comment https://forums.phpfreaks.com/topic/208885-variable-wont-display/#findComment-1091101 Share on other sites More sharing options...
otester Posted July 26, 2010 Author Share Posted July 26, 2010 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? Link to comment https://forums.phpfreaks.com/topic/208885-variable-wont-display/#findComment-1091226 Share on other sites More sharing options...
Pikachu2000 Posted July 26, 2010 Share Posted July 26, 2010 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'); Link to comment https://forums.phpfreaks.com/topic/208885-variable-wont-display/#findComment-1091238 Share on other sites More sharing options...
otester Posted July 26, 2010 Author Share Posted July 26, 2010 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! Link to comment https://forums.phpfreaks.com/topic/208885-variable-wont-display/#findComment-1091240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.