Last active
October 5, 2015 13:31
-
-
Save oliveratgithub/8d6542a61845a79bd917 to your computer and use it in GitHub Desktop.
Vanilla Community Forum custom Theme hook to add custom apple-touch-icons and favicon to your site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!defined('APPLICATION')) exit(); | |
class MythemenameThemeHooks implements Gdn_IPlugin | |
{ | |
/** | |
* No setup required | |
*/ | |
public function Setup() { } | |
/** | |
* No disable actions required | |
*/ | |
public function OnDisable() { } | |
/** | |
* Add icons to page <head></head> | |
*/ | |
public function base_render_before($Sender) { | |
if (is_object($Sender->Head)) { | |
// Automatically grab the current Theme's name | |
$mytheme = Gdn::config('Garden.Theme'); | |
// Seting a custom Theme Favicon | |
$Sender->Head->setFavIcon('/themes/'.$mytheme.'/design/favicon.png'); | |
// Setting for chaning the Safari iOS Status Bar Appearance | |
// Docs: https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html | |
$Sender->Head->addTag('meta', array('name' => 'apple-mobile-web-app-capable', 'content' => 'yes')); | |
$Sender->Head->addTag('meta', array('name' => 'apple-mobile-web-app-status-bar-style', 'content' => 'black')); | |
// Add custom apple-touch-icons from Theme folder | |
// Docs: | |
// • Official: https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html | |
// • Inofficial: https://mathiasbynens.be/notes/touch-icons | |
$Sender->Head->addTag('link', array('rel' => 'apple-touch-icon-precomposed', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-precomposed.png')); | |
$Sender->Head->addTag('link', array('rel' => 'apple-touch-icon', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-iphone.png')); | |
$Sender->Head->addTag('link', array('rel' => 'apple-touch-icon', 'sizes' => '76x76', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-ipad.png')); | |
$Sender->Head->addTag('link', array('rel' => 'apple-touch-icon', 'sizes' => '120x120', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-iphone-retina.png')); | |
$Sender->Head->addTag('link', array('rel' => 'apple-touch-icon', 'sizes' => '152x152', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-ipad-retina.png')); | |
// ...and custom favicon for Android & Nokia Devices | |
// Docs: https://mathiasbynens.be/notes/touch-icons | |
$Sender->Head->addTag('link', array('rel' => 'icon', 'sizes' => '192x192', 'content' => '/themes/'.$mytheme.'/design/apple-touch-icon-ipad-retina.png')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would write line 22 like that:
$mytheme = Gdn::config('Garden.Theme');
so that it is a cut & paste snippet with zero configuration.