Stampa
Categoria: Joomla
Visite: 47031

Valutazione attuale: 5 / 5

Stella attivaStella attivaStella attivaStella attivaStella attiva
 

Joomla3-Google Font 120x90

The Protostar Template for Joomla 3 comes included with the base Joomla installation. Admin interface allows you to set only the heading font with the google font. I can show you how to add a google font for the body tag. 

 In order to add this feature I found 2 ways. The 1st one is very easy and fast but it is not enough elegant and not very professional. The first method consists to change only the index.php without change the interface of the template manager. The second method will provide a new field in the template manager module for the "Google Font Name for Body" and every time we want to change the google font for body, we will not need to edit the index.php, but just open Joomla Back-end -> Template Manager and type the font in the new field.

The following changes were applied to Joomla 3.2.3 and Joomla 3.3 (may 4th 2014) 


METHODS

  1. Changing only the index.php
  2. Changing the admin interface for the template protostar: module, language (labels, description, name) and the index.php

 

METHOD 1 - CHANGING ONLY THE INDEX.PHP

  1. Locate the index.php under the "joomla root"/templates/protostar
    use an ftp program to browse the server folders of your site
  2. Edit the index.php
    You can use a simple notepad or a better editor like notepad++
  3. Search for "google" word
  4. Now we have to duplicate the line with the link to the fonts.googleapis.com/css?family and insert the font for the body
  5. See the following code and images. 
<?php
// Use of Google Font
if ($this->params->get('googleFont'))
{
?>
	<link href='//fonts.googleapis.com/css?family=<?php echo $this->params->get('googleFontName');?>' rel='stylesheet' type='text/css' />
	<link href='//fonts.googleapis.com/css?family=Mako' rel='stylesheet' type='text/css' />
	<style type="text/css">
		h1,h2,h3,h4,h5,h6,.site-title{
			font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFontName'));?>', sans-serif;
		}
		body {
			font-family: Mako, sans-serif;
		}
	</style>

 

 You have to enable the google font for heading, as you can see it is inside an if ...

 

 

Screenshots method 1

 

Method-1 Screenshot-Index
Method-1 Screenshot-Index
Method-1 Screenshot-Protostar
Method-1 Screenshot-Protostar

 


METHOD 2 - CHANGING THE ADMIN INTERFACE

This way is more elegant and flexible way.

Goal is add a field on template Manager for the protostar: Google Font for Body

 

New field in the module of the Template Manager

Edit the file templateDetails.xml located in the folder /templates/protostar.

The fierst field is the original field, I duplicated it and changed the name, label and description.

<field name="googleFontName" class="" type="text" default="Open+Sans"
label="TPL_PROTOSTAR_FONT_NAME_LABEL"
description="TPL_PROTOSTAR_FONT_NAME_DESC" />
					
<field name="googleFontNameBody" class="" type="text" default="Open+Sans"
label="TPL_PROTOSTAR_FONT_NAME_BODY_LABEL"
description="TPL_PROTOSTAR_FONT_NAME_BODY_DESC" />

 

Language Override

Create one or more file on /administrator/language/overrides

In alternative you can use the Joomla Language Override Interface under the menu Components. BTW after you created the file you fille find the entries in component->Language->Override.

TPL_PROTOSTAR_FONT_DESC="Load a Google font for the headings and body (H1, H2, H3, etc. and BODY)"
TPL_PROTOSTAR_FONT_LABEL="Google Font for Headings"
TPL_PROTOSTAR_FONT_NAME_BODY_DESC="Example: Open+Sans or Source+Sans+Pro"
TPL_PROTOSTAR_FONT_NAME_BODY_LABEL="Google Font Name Body"

 

index.php

Locate the index.php under the "joomla root"/templates/protostar 
use the ftp to browse the server folders of your site

 

<?php
	// Use of Google Font
	if ($this->params->get('googleFont'))
	{
	?>
		<link href='//fonts.googleapis.com/css?family=<?php echo $this->params->get('googleFontName');?>' rel='stylesheet' type='text/css' />
		<link href='//fonts.googleapis.com/css?family=<?php echo urlencode($this->params->get('googleFontNameBody'));?>' rel='stylesheet' type='text/css' />
		<style type="text/css">
			h1,h2,h3,h4,h5,h6,.site-title{
				font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFontName'));?>', sans-serif;
			}
			body {
				font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFontNameBody'));?>', sans-serif;
			}
		</style>

The php urlencode(...) is useful to prevent a blank space on font name. It will works but will generate an error on html5 validation.

Please add urlencode(...) also in the first link. 

 

Screenshots method 2

Method-2 Screenshot-Index
Method-2 Screenshot-Index
Method-2 Screenshot-Language-Manager-Menu
Method-2 Screenshot-Language-Manager-Menu
Method-2 Screenshot-Language-Manager-Override
Method-2 Screenshot-Language-Manager-Override
Method-2 Screenshot-Template-Manager
Method-2 Screenshot-Template-Manager

 


IMPORTANT NOTE

Since Joomla 3.4.3 my google body fonts does not work.

I had to create a new style /style just before the /head and I copied inside the body style. This is not so elegant but it's the last work around found  ;-)

 


 

 

DISQUS - Leave your comments here