View Full Version : dynamic meta name / description
mistersmith307820
09-12-2009, 11:29 AM
Is there a simple way in dreamweaver to make the the meta descriptions and titles dynamic?
My site is built from PHP templates so the names / descriptions of each page are the same (from the template) and I would like each one to be more relevant to the individual page ie: include the product name.
thanks!
Donovan
tom92909
09-12-2009, 02:13 PM
I can think of 2 possible solutions for you.
1. Dynamic with an include file.
2. Dynamic pulling from a SQL table.
The external include file would be easier to explain here, so I'll give you a quick example...
Add the following line to any page you want to include metatags to
<?php include ('my_metatags.php'); ?>
<html>
<head>
<?php echo MY_META; ?>
</head>
<body>
</body>
</html>
Create a file called my_metatags.php
Below are the contents that can be added to any and/or all pages on your website.
<?php
define('MY_META' , '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="">
<meta name="description" content="">
');
?>
SOJO web
09-12-2009, 07:26 PM
Donovan,
Here is the code I like to use to create page titles dynamically... this will generate the page title based on the page name.
// CURRENT PAGE
$currentPage = basename($_SERVER['SCRIPT_NAME'], '.php');
$currentPage = str_replace('_', ' ', $currentPage);
if ($currentPage == 'index') { $currentPage = 'home'; }
$currentPage = ucwords($currentPage);
Please note that it will do a replace to underscores with a space and then will capitalize the first letter of each word. So "this_page.php" becomes "This Page". You just then need to echo the $currentPage variable within your title.
Regards,
Brian
Jimmy Wu
09-14-2009, 10:36 AM
Both those solutions look great. Thanks for helping out on this issue.
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.