Top

PHP Auto Website Title

+ 0 likes
Please Register to submit score.
Average Score  3.0
Scores Submitted  2
Date Added  Apr 28, 2008
Last Updated  Apr 28, 2008
Tags  auto  code  comment  function  functions  help  jonesy  jonesy44  php  quote  strreplace  title  variable  web  webpage  website 

Introduction

This simple PHP function is pretty handy if you want your websites pages in the title without having to name individual ones.

It will look like:
Quote:
MyWebsite | Index

Quote:
MyWebsite | Gallery

Quote:
MyWebsite | Forums

etc..

paste the code into your "functions" file, or any webpage which is included in every page you have
(Reminder: To include a webpage, use 'include("webpage.php");')
You can of course put the function in each page, but that's just annoying .. :P

then, in each webpage you want the title to appear, put

Code:
<?php
include("the_function_webpage");
title();
....
?>


I've quoted each line to show the people who don't do PHP, how the function works a little better

Rate it, post comments :P

Grab the Code

Comments

  (7)  RSS
jonesy44
Comments: 852
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 2:15 pm
Feel free to post any feedback

*Bummp to the comments page xD*
Hawkee
Comments: 464
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 4:28 pm
I think its better to use a switch statement to tie the file names to better page titles that you define separately. If you only use the words in the file names your page titles will be very short and limited. In other words this won\'t help you rank in the search engines very well.
jonesy44
Comments: 852
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 5:23 pm
I can agree to that, you\'re a hard one to compete with, Hawkee :P
But, learn from the best eh? ;-)

what do yoou mean by a switch statement? :-s
Hawkee
Comments: 464
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 5:35 pm
Something like:

Code:

switch($page)
{
    case \"index\":
        $title = \"Homepage Title\";
        break;

    case \"about\":
        $title = \"About Us Title\";
        break;
}


jonesy44
Comments: 852
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 5:39 pm
then put

<title>\' .$title. \'</title>

?
Hawkee
Comments: 464
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 28, 2008 6:24 pm
Sure, or use it as a template variable. I use templates so my PHP code doesn\'t mix with any html. Look into the Smarty template engine to see what I mean.
jonesy44
Comments: 852
 
PHP Snippet:  PHP Auto Website Title
Posted on Apr 29, 2008 4:24 am
\'kay, will do. thanks for the info on that :P
I always thought case\'s / break\'s were JS for some reason :s

Anyways, i\'ll have a look into it, and perhaps release a better version xD

Please Register or Login to start posting comments.
Bottom