The content of the head tag is shared (external file is included)

The method of taking the external file by using PHP and SSI in body tag is generally used well on the homepage by the technique often used. After coming to have taken the file by using PHP or SSI for the menu and the affiliate, it became very easy to manage the file. On the other hand, the example of taking the external file too much is not seen in the head tag. Is this because description, keywords in the meta tag, and the content of the title tag are different according to the page?

I took the common external file by using PHP in the head tag even if description, keywords in the meta tag, and the content of the title tag were different according to the page, made the content of the head tag another file, and shared. Next, it explains the method.

The character string is defined from the head tag by previous.

Description, keywords in the meta tag, and the content of the title tag are registered in the character string just before the head tag as follows.

<?php $des_c = "Page description"; ?>
<?php $key_w = "Keywords"; ?>
<?php $title = "Page title"; ?>

The registered character string is used in the head tag made a external file.

The registered character string is displayed in the place of the character string for which it wants to use in the head tag made a external file as follows. It displays in addition and it doesn't care in any way to use it in the body tag even if it uses it. The page can be found by using title ($title) in the H1 tag as well as the title.

<?php echo $des_c; ?>
<?php echo $key_w; ?>
<?php echo $title; ?>

Example of content of head tag (common external file)

The example of the content of the head tag made a external file is as follows. The character string registered in this file is progressed. It is an example for me.

<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv"Content-Script-Type" content"text/javascript" />
<meta property="og:title" content="<?php echo $title; ?>" />
<meta property="og:image" content="http://domain/***/***.jpg" />
<meta property="fb:app_id" content="123456789012345" />
<meta property="fb:admins" content="123451234567890" />
<?php
if ($des_c != ""){echo "<meta name=\"description\" content=\"$des_c\" />\n";}
if ($key_w != ""){echo "<meta name=\"keywords\" content=\"$key_w\" />\n";}
?>
<title><?php echo $title; ?></title>
<link rel="shortcut icon" href="http://domain/favicon.ico" />
<link rel="icon" href="http://domain/favicon.ico" />
<link rel="alternate" href="http://feeds.domain/****" type="application/rss+xml" title="RSS" />

Although "$title" certainly exists, since there may be no contents, "$des_c" and "$key_w" make a condition judgment so that the meta-tag itself may not be generated in this case.

How to include the external file in the head tag using PHP page

After all, the method of taking the registration of the character string and the external file in the head tag (include) does as follows on the PHP page. The file name in which the content of the head tag is described as an example It is assumed "head1.inc". Because it is a file that include is done, inc might be better though any extension is not cared.

<?php $des_c = "Page description"; ?>
<?php $key_w = "Keywords"; ?>
<?php $title = "Page title"; ?>
<head>
<?php include($_SERVER['DOCUMENT_ROOT'].'/***/head1.inc'); ?>
<link rel="stylesheet" href="../com/style.css" type="text/css" media="all" />
<?php include($_SERVER['DOCUMENT_ROOT'].'/***/head2.inc'); ?>
</head>

Thus, the code became very easy. As for that describes the content of the head tag, because a lot of kinds are unnecessary, it becomes easy to manage this file. A selfish change by the homepage builder and writing mistake disappears.

A style sheet is read with a relative address in this way. This is for validating a style sheet with the software of a homepage builder, Expression Web3, etc. Scripts, such as Javascript, are read after the style sheet.

Disadvantage that makes content of head tag external file

It is not only good when the content of the head tag is made a external file. It might be bad as follows. Therefore, I am using this method only to display the log file in the past of the repair technology information bulletin board operated only by the editor.