This object is in archive! 

How to change favicon using head.phtml into a custom theme?

Archived mario b. 11 years ago

I'm trying this:


file head.phtml into my themes/my_theme/templates/layout but favicon is not working!

  1. <?php $this->headLink()->prependStylesheet($this->stylesheetSrc('global.css', null, false))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('theme.css', null, true))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('ie-styles.css', null, true), "screen, projection", "lt IE 9")?>

    <?php $this->headLink()->headLink(array('rel' => 'favicon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'PREPEND');?>

    <?php $this->headLink()->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'PREPEND');?>


    <?php $this->headScript()->offsetSetFile(-100, $this->javascriptSrc('jquery.js', null));?>

    <?php $this->headScript()->offsetSetFile(-99, $this->javascriptSrc('application.js', null));?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('global.js', null, false))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('scripts.js', null, true))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('ie-script.js', null, true), 'text/javascript', array('conditional' => 'lt IE 9'))?>


    <?php echo $this->headTitle() . PHP_EOL ?>

    <?php echo $this->headMeta() . PHP_EOL ?>

    <?php echo $this->headLink() . PHP_EOL ?>

    <?php echo $this->headScript() . PHP_EOL ?>

    <?php echo $this->headStyle() . PHP_EOL ?>

Replies (8)

photo
1

Mario, click "Show Source Code" in your browser and take a look what you have there.

Maybe the reason is in wrong path. As I see you have tried to override head.phtml file in your theme folder. Make sure that path to head.phtml is relative to original.

photo
1

I've checked paths but all seems to be correct! In fact I'm able to change head.phtml and see variations on source code.

Now I've forced favicon, but I don't like this:


  1. <?php $this->headLink()->prependStylesheet($this->stylesheetSrc('global.css', null, false))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('theme.css', null, true))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('ie-styles.css', null, true), "screen, projection", "lt IE 9")?>

    <?php $this->headLink()->headLink(array('rel' => 'favicon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'APPEND');?>

    <?php $this->headLink()->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'APPEND');?>


    <?php $this->headScript()->offsetSetFile(-100, $this->javascriptSrc('jquery.js', null));?>

    <?php $this->headScript()->offsetSetFile(-99, $this->javascriptSrc('application.js', null));?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('global.js', null, false))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('scripts.js', null, true))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('ie-script.js', null, true), 'text/javascript', array('conditional' => 'lt IE 9'))?>


    <?php echo $this->headTitle() . PHP_EOL ?>

    <?php echo $this->headMeta() . PHP_EOL ?>

    <?php echo $this->headLink() . PHP_EOL ?>

    <?php echo '<link rel="shortcut icon" href="'.$this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico').'" type="image/x-icon" />'. PHP_EOL ?>

    <?php echo '<link rel="favicon" href="'.$this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico').'" type="image/x-icon" />'. PHP_EOL ?>

    <?php echo $this->headScript() . PHP_EOL ?>

    <?php echo $this->headStyle() . PHP_EOL ?>

and the final source now looks like


  1. <!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>


    <title>useresponse</title>

    <meta http-equiv="content-type" content="text/html;charset=utf-8" />

    <link href="http://localhost/useresponse/public/static/1cdc7bd17eb3519a7b8e984d03ab7980_minify.css" media="screen" rel="stylesheet" type="text/css" />

    <!--[if lt IE 9]> <link href="http://localhost/useresponse/public/themes/my_theme/assets/css/ie-styles.css" media="screen, projection" rel="stylesheet" type="text/css" /><![endif]-->

    <link rel="shortcut icon" href="http://localhost/useresponse/public/themes/my_theme/assets/images/favicon.ico" type="image/x-icon" />

    <link rel="favicon" href="http://localhost/useresponse/public/themes/my_theme/assets/images/favicon.ico" type="image/x-icon" />

    <script type="text/javascript" ><![endif]-->

    <script type="text/javascript">

photo
1

Mario, I really can't understand what the problem to change favicon.

You simply need to override application/templates/layout/head.phtml by copying to your theme folder as shown on attached image as example.


0HidTz0mF8tKP12I5cv5


Then, find the folllowing lines:

  1. <?php $this->headLink()->headLink(array('rel' => 'favicon', 'type' => 'image/x-icon', 'href' => '/public/assets/images/favicon.ico'), 'PREPEND');?>
  2. <?php $this->headLink()->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => '/public/assets/images/favicon.ico'), 'PREPEND');?>

and change favicon paths to yours.


To change favicon is as easy as falling off a log.

photo
1

Exactly what I tried to do, same folders structure! But this is not working for me.

I've just changed head.phtml as you suggested and the tag for favicon is disappeared from home page html source...

No way...

Is it possible that the problem is caused by the fact that I'm trying to put my favicon into the customized theme folder?


$this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'PREPEND');?>


My code now:

  1. <?php $this->headLink()->prependStylesheet($this->stylesheetSrc('global.css', null, false))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('theme.css', null, true))?>

    <?php $this->headLink()->appendStylesheet($this->stylesheetSrc('ie-styles.css', null, true), "screen, projection", "lt IE 9")?>

    <?php $this->headLink()->headLink(array('rel' => 'favicon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'PREPEND');?>

    <?php $this->headLink()->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => $this->baseUrl('/public/themes/my_theme/assets/images/favicon.ico')), 'PREPEND');?>


    <?php $this->headScript()->offsetSetFile(-100, $this->javascriptSrc('jquery.js', null));?>

    <?php $this->headScript()->offsetSetFile(-99, $this->javascriptSrc('application.js', null));?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('global.js', null, false))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('scripts.js', null, true))?>

    <?php $this->headScript()->appendFile($this->javascriptSrc('ie-script.js', null, true), 'text/javascript', array('conditional' => 'lt IE 9'))?>


    <?php echo $this->headTitle() . PHP_EOL ?>

    <?php echo $this->headMeta() . PHP_EOL ?>

    <?php echo $this->headLink() . PHP_EOL ?>

    <?php echo $this->headScript() . PHP_EOL ?>

    <?php echo $this->headStyle() . PHP_EOL ?>

photo
1

Mario,

Do you see the favicon by link in browser? What is the problem of changing default favicon to yours? Just make sure that after system update you'll need to replace it one more time

photo
1

mario barretta wrote:

Is it possible that the problem is caused by the fact that I'm trying to put my favicon into the customized theme folder?
Exactly not, Mario.

Maybe browser cache?

One more question: Are you sure that the proper theme was chosen in Administration -> Interface?


VpghpAuSaGkueTMkxKtZ

photo
1

Stas Kuzma wrote:

Mario,

Do you see the favicon by link in browser? What is the problem of changing default favicon to yours? Just make sure that after system update you'll need to replace it one more time

I'm checking source code of the page and there is not

  1. <link rel="shortcut icon" href="http://feedback.my_theme.com/public/themes/my_theme/assets/images/favicon.ico" type="image/x-icon" />
  2. <link rel="favicon" href="http://feedback.my_theme.com/public/themes/my_theme/assets/images/favicon.ico" type="image/x-icon" />

I'm not looking only at the browser output.


And no, My_theme is selected correctly in fact I've changed other things as logo and colors.

photo
1

Your custom theme must be active in interface settings area.

After all changes you are making must also be under the current selected theme.

Replies have been locked on this page!