Actions

Difference between revisions of "Customising the dynamic page title"

From Joomla! Documentation

(Updated with more info.)
Line 1: Line 1:
To customize the page title to add the site name followed by the document title, edit index.php in the template that you are currently using. For example, directly after the <head> tag add the following to show "Site Name - Page Name" as the browser's page title:
+
This will allow you to change the global page title across the entire site. You may customize it to your own liking within your own templates files.
  
 +
The code needs to go just after the opening <nowiki><head></nowiki> element and before <nowiki><jdoc:include type="head" /></nowiki> element.
 +
 +
 +
Document title: <strong><nowiki>$document->title</nowiki></strong>
 +
 +
Sitename: <strong><nowiki>$mainframe->getCfg('sitename')</nowiki></strong>
 +
 +
 +
How it would look(currently set to "Document title - Sitename"):
 +
<source lang="php">
 +
<?php
 +
$document =& JFactory::getDocument();
 +
$document->setTitle($document->title . " - " . $mainframe->getCfg('sitename'));
 +
?>
 +
</source>
 +
 +
 +
Example (template coding may vary):
 
<source lang="php">
 
<source lang="php">
 +
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 +
<html xmlns="http://www.w3.org/1999/xhtml">
 +
<head>
 
  <?php
 
  <?php
 
  $document =& JFactory::getDocument();
 
  $document =& JFactory::getDocument();
  $document->setTitle($mainframe->getCfg('sitename') . " - " . $document->title);
+
  $document->setTitle($document->title . " - " . $mainframe->getCfg('sitename'));
 
  ?>
 
  ?>
 +
<jdoc:include type="head" />
 +
.... rest of template file.
 
</source>
 
</source>
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks 1.5]]
 
[[Category:Tips and tricks 1.5]]
 
[[Category:Tutorials]][[Category:Component Development]]
 
[[Category:Tutorials]][[Category:Component Development]]

Revision as of 00:29, 7 March 2011

This will allow you to change the global page title across the entire site. You may customize it to your own liking within your own templates files.

The code needs to go just after the opening <head> element and before <jdoc:include type="head" /> element.


Document title: $document->title

Sitename: $mainframe->getCfg('sitename')


How it would look(currently set to "Document title - Sitename"):

 <?php
 $document =& JFactory::getDocument();
 $document->setTitle($document->title . " - " . $mainframe->getCfg('sitename'));
 ?>


Example (template coding may vary):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <?php
 $document =& JFactory::getDocument();
 $document->setTitle($document->title . " - " . $mainframe->getCfg('sitename'));
 ?>
<jdoc:include type="head" />
.... rest of template file.