Jump to content

Best technique for the head element?


nubby

Recommended Posts

So, I know xhtml/css/javascript pretty well and I just started learning php recently. I am going through all my current sites and fixing things so my code looks a lot better and I get better coding techniques. But I was wondering what is the best way to include title element on all pages without having to individually change each page? Would I just start the title string on the index page and call for $title string on all my other pages so when I want to edit it I only have to do that on the index page? Same with keywords and description? Can someone explain how I would do this a little better? Sorry I am really really new to php.

Link to comment
https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/
Share on other sites

What's up?

 

I have something like this in my config files.  Then have that file required before the html code.

 

<?php
$sitename = "My Web Site";
?>

 

Then for the title ...

 

<title><?php echo $sitename; ?></title>

 

I keep the html header stuff in another file called header, which I require on every page.

 

Hope it helps.

 

What's up?

 

I have something like this in my config files.  Then have that file required before the html code.

 

<?php
$sitename = "My Web Site";
?>

 

Then for the title ...

 

<title><?php echo $sitename; ?></title>

 

I keep the html header stuff in another file called header, which I require on every page.

 

Hope it helps.

 

 

So for all your sites you have meta and head element information like title, keywords, description in a file called config.php? And then basically in the header do:

 

<title><?php echo $sitename; ?></title>

 

But then what do you do for keywords and all that? Sorry if I sound like the biggest beginner.  :-X

You could do the same ...

 

<meta name="<?php echo $config_keyword; ?>" content="<?php echo $config_description; ?>">

 

I would just use something like this, make a header file, then use it in in all of your files.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta name="Milk" content="Moo, Moo, Moo!">
<title>Milk Jugs</title>
<link href="ss.css" rel="stylesheet" type="text/css" />
<body>
<div id="main">

 

Using variables is nice too, but if you have it all in one file, like config.php or header.php it is easier to modify.

 

<?php
require('header.php');

... content goes here ...

?>

going on that i would recomend this

 

header.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta name="<?php echo $meta_name;?>" content="<?php echo $content;?>">
<title><?php echo $title;?></title>
<link href="ss.css" rel="stylesheet" type="text/css" />
<body>

 

then index.php

<?php 
$meta_name = "Meta Name";
$content= "content";
$title = "Page title";
require_once 'header.php';
?>

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.