Jump to content

Calling title and meta dynamically


myotch

Recommended Posts

I looked for and found a similar thread, but the resulting bunny trail was specific to that OP's situation.

 

I'll jump right to it.  I've seen this done on another site, and I want to implement it the same way on another site I'm doing.

 

Any typical page of the site will have includes files, quite a few of them nested like those little russian dolls.

 

For instance, the about us page calls includes/header.php...

<?php include("includes/header.php") ?>

 

...and the header.php file calls the meta information...

<?php include("includes/site_titles.php") ?>
<?php include("includes/site_keywords.php") ?>
<?php include("includes/site_descriptions.php") ?>

 

...and those files have arrays...

<?php
$SITE_TITLES = array();
$SITE_TITLES['about_us'] = $SITE_TITLE . " About Us";
$SITE_TITLES['page2'] = $SITE_TITLE . " page2";
$SITE_TITLES['page3'] = $SITE_TITLE . " page3";
?>

 

...and going back to our header.php, in the appropriate place, we echo the title and meta...

 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?=$SITE_TITLES[$page]?></title>
<meta name="description" content="<?php echo $SITE_DESCRIPTIONS[$page]?>" />
<meta name="keywords" content="<?php echo $SITE_KEYWORDS[$page]?>" />

 

...which, when uploaded, *should* display in "view source" the correct title tag, keywords, and description.

 

However, when I do this, I get empty tags.

 

Am I supposed to define the site variable ($SITE)?  Or am I doing something else wrong?  I have the original source where I first saw this  in Dreamweaver, but am unable to find a file where $SITE and all it's little buddies are defined to correspond with a file name ('about' = ("about.php").

 

Any help or advice is greatly appreciated.

 

Myotch

 

 

Link to comment
https://forums.phpfreaks.com/topic/211921-calling-title-and-meta-dynamically/
Share on other sites

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.