Skip to content

Instantly share code, notes, and snippets.

@oliveratgithub
Last active October 5, 2015 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliveratgithub/8d6542a61845a79bd917 to your computer and use it in GitHub Desktop.
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
<?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'));
}
}
}
@R-J
Copy link

R-J commented Sep 30, 2015

I would write line 22 like that: $mytheme = Gdn::config('Garden.Theme'); so that it is a cut & paste snippet with zero configuration.

@oliveratgithub
Copy link
Author

Thanks @R-J for the great hint, I updated the code accordingly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment