kade119 Posted May 5, 2010 Share Posted May 5, 2010 I have my header file set as an include, so each page at the moment uses the same description and page title. How could I use PHP to make the meta information dynamic? Quote Link to comment https://forums.phpfreaks.com/topic/200837-dynamic-meta-description-and-title/ Share on other sites More sharing options...
Pikachu2000 Posted May 5, 2010 Share Posted May 5, 2010 Define them as variables before including the header page, and just echo them out in the included script. <?php $title = "Some String of stuff"; $desc = "Some other string of stuff"; include('header.php'); //body include('footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/200837-dynamic-meta-description-and-title/#findComment-1053841 Share on other sites More sharing options...
kade119 Posted May 5, 2010 Author Share Posted May 5, 2010 perfect thanks man Quote Link to comment https://forums.phpfreaks.com/topic/200837-dynamic-meta-description-and-title/#findComment-1053869 Share on other sites More sharing options...
stuartbates Posted May 5, 2010 Share Posted May 5, 2010 With meta-tags always a good idea to set default options because as your website grows there's a good chance they will get over looked. So use a conditional like: if (!isset($title)){ echo '<title>Default Page Title</title>'; } else { echo '<title>' . $title . '</title>'; } You might also want to consider using the database to drive the meta tags - particularly if you have any form of catalogue. Quote Link to comment https://forums.phpfreaks.com/topic/200837-dynamic-meta-description-and-title/#findComment-1053873 Share on other sites More sharing options...
kade119 Posted May 6, 2010 Author Share Posted May 6, 2010 so if i forget to add the title var on a specific page it will use the default title, is that correct? could you show me how to set it up to use DB functionality? thanks man!! Quote Link to comment https://forums.phpfreaks.com/topic/200837-dynamic-meta-description-and-title/#findComment-1053903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.