Display Web Browser Specific Message

By default, WordPress comes with number of pre-built functions that can be really handy sometimes. It also gives you the flexibility of using number of Global Variables, particularly the browser detecting variables are simply awesome. You can use these variables in so many ways. One such feature could be displaying browser specific message. Let's say you designed a site with advanced technologies, something old browsers can not render properly. In such case, you can encourage your visitor to upgrade or simply to install a different browser that you know would display your site properly. Here is a screenshot of a site with similar idea. This is how you can do it.
global $is_chrome, $is_winIE;
   if ($is_winIE) { 
      echo '<div id="message">Windows Internet Explorer.</div>';
   } elseif ($is_chrome) {
      echo '<div id="message">Google Chrome.</div>';
   } else { 
      echo '<div id="message">Unknown Browser Detected!</div>';
You can simply copy and paste this snippet directly anywhere on your template pages. However, if you want to organize all of your custom functions in one place, you can wrap this snippet within a function and call it from anywhere you like. You can do it like this:
function ib_browser_message() {
   // snippet from above goes here.
Place the function on your functions.php page and call it like this on your theme template:
<?php ib_browser_message(); ?>
That's all. You are done with your snippet. Get creative with this snippet and use it anyway you like. Good luck.


Commenting is disabled.