Jump to content

Recommended Posts

Hi, i need help for add custom code like javascript or css to head, i have function for it but i'm confused  :confused:, here is code:

 

header.php

<?php
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo EMS_CAD; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<?php if (function_exists("add_to_head")) { echo add_to_head(); } ?>
</head>?>

includes.php

<?php
$page_head_tags = "";
function add_to_head($tag=""){
global $page_head_tags;

if(!stristr($page_head_tags, $tag)){
	$page_head_tags .= $tag."\n";
}
}
?>

index.php

<?php add_to_head("<link rel='stylesheet' href='blue.css" type='text/css' media='screen' />");?>

Link to comment
https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/
Share on other sites

header.php

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo EMS_CAD; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<?php if (function_exists("add_to_head")) { echo add_to_head(); } ?>
</head>

 

Try that. You only need to open PHP tags when you plan on executing PHP code.

 

Also:

index.php

<?php add_to_head("<link rel='stylesheet' href='blue.css' type='text/css' media='screen' />");?>

 

You had a syntax error with the double quote after blue.css.

Maybe my mistake, i review my code but here no errors, why show me empty delimiter :confused:

 

header_includes.php

<?php
$page_head_tags = "";

function add_to_head($tag=""){
global $page_head_tags;

if(!stristr($page_head_tags, $tag)){
	$page_head_tags .= $tag."\n";
}
}?>

 

header.php

<?php
include("header_includes.php");
?>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo EMS_CAD; ?></title>
<meta name="description" content="EMS-CAD, Arhitektura">
<meta name="keywords" content="EMS-CAD, Arhitektura">
<link rel="stylesheet" href="stil.css" type="text/css" media="screen" />
<?php if (function_exists("add_to_head")) { echo add_to_head(); } ?>
</head>

<body>

<table class="table" cellspacing="0" cellpadding="0" align="center">
    <tr>
        <td valign="top" nowrap>        
<table class="table" cellspacing="0" cellpadding="0">
	<tr>
		<td>
		<img border="0" src="sliki/header1.jpg" width="400" height="200"></td>
		<td class="header"><div class="top">
		<a href="index.php" title="<?php echo HOME;?>" class="prozirnost"><img src="sliki/naslovna.gif" border="0" alt="<?php echo HOME;?>"></a> <img src="sliki/tocki.gif"> <a href="kontakt.php" title="<?php echo MSG;?>" class="prozirnost"><img src="sliki/mail.gif" border="0" alt="<?php echo MSG;?>"></a> <img src="sliki/tocki.gif">
		<a href="#" title="<?php echo MAP;?>" class="prozirnost"><img src="sliki/mapa.gif" border="0" alt="<?php echo MAP;?>"></a></div></td>
	</tr>
</table>

 

index.php

<?php
include_once("header.php");
add_to_head("<link rel='stylesheet' href='blue.css' type='text/css' media='screen' />");?>

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.