Jump to content

How do I create unique meta information in <head> for each page


Recommended Posts

I'm using inc.header.php that I include in every page. Is this a proper procedure?

 

The inc.header.php contains all my header information, because of that I can't just create different <head> information on every page since it is already included in inc.header.php.  But, how do I make it unique?  Should I just not include <head> info in inc.header.php and instead include it in every page? But that solution is too lengthy to implement if you have 50 pages.

 

Or is there a dynamic way of generating unique <head> meta information from page description and title.

 

 

Please let me know

Ben

usually you would draw data/information from a database for such a thing.  have a field like 'meta_title' for each record, and have a unique title stored in that field.

\

I guess that would be an expert way of doing it, but is there a newbie way?

 

whats so hard about drawing data from a database? just a simple select statement. what does your inc.header.php page look like right now? Instead of hard coding the meta data in you could just get it from a data base, and echo variables that hold the meta data

You see, I have very limited php skills, I'm a designer by trade and coding doesn't come natural with me.

 

Maybe you can help me modify this script that was already made by a coder sometime ago.

 

Ok, so this script generates title for the ad page.

 

 <h1><?PHP
$ad = "";
$ad = $db->get_row("SELECT user_id,title,type,body,date_update,image,uid FROM ad WHERE id = '$adid'");

//	$subject = htmlspecialchars($ad->title, ENT_QUOTES); 
//	$subject = urlencode($ad->title);
$subject = str_replace('\'', '', $ad->title);
$subject = str_replace('"', '', $subject);
$subject = str_replace('&', 'and', $subject);

$ad->user_id;

$poster = $db->get_row("SELECT id,first_name,last_name,email_address,phone_office,phone_ext,phone_mobile,co_name,co_name_url,co_address3,co_city,co_state,co_country,url FROM user WHERE id = '$ad->user_id'");

        
        
  echo $ad->title;
  ?>
    </h1>

 

 

The  echo $ad->title; is also used like this to generate title for the page

 

<head>
<title><?PHP echo $ad->title;  ?></title>
</head>

 

This code works, but the problem is, the coder included that <head> information in the same page file. I would it to be included in the inc.header.php.  But when I do, it doesnt render the page title. The code is meant to work only where <head> is found in the same file. How can I fix this issue?

 

usually you would draw data/information from a database for such a thing.  have a field like 'meta_title' for each record, and have a unique title stored in that field.

\

I guess that would be an expert way of doing it, but is there a newbie way?

 

for the record, i'm hardly an expert.

 

it's really not a difficult process as mike stated.  this is a help forum, and people here are willing to help get other people going on such tasks.  once you get going with databases, you're going to wonder how you ever did without.

 

seems you figured it out you say .. don't hesitate to post here though, just make sure you state very clearly any issues you're having with your current code, any error(s) that might also be associated, and as detailed a description (without being too lengthy), about what caused the error(s) and/or what you are trying to achieve.

 

keep in mind though, this is a help forum, not a do for you forum.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.