Check out the latest documentation.

Theme Developers

Using 51Degrees Properties within a Theme

  1. With the plugin installed and activated, login as a user account with sufficient permissions to customise a themes PHP code.
  2. Navigate to the theme editor by clicking on "Appearance" and then "Editor" (in the left hand menu). This will display the code of the current theme.

    For this tutorial the default theme, "Twenty Eleven", is in use.

  3. In the editor screen look on the right hand side menu and find the file name that reads "Main Index Template (index.php)" and click it.
  4. The main screen will change to show all the PHP code contained within this file.

  5. Within this file find the following lines of code.
  6. <div id="primary">

    <div id="content" role="main">

    They are located near the beginning of the file after the file description comments.



    As the $_51d variable is declared in global scope, you will need to use the global keyword to use it.



    Also note that that all properties are given as strings, even if the property is boolean. This is to ensure data consistency.

    Add the following code after the lines found above.



    <?php

      global $_51d;

      if($_51d['IsMobile']=='True') {

        echo "Welcome Mobile Visitor";

      }

      else {

        echo "Welcome Non-Mobile Visitor";

      }

    ?>

    The changes should be similar to the following screen shot.

    The addition of this small piece of code within the Wordpress theme will print a message on the main index page of your Wordpress site. The message will change depending on whether the visitor is using a mobile device or a non-mobile device.

All the properties exposed by the plugin are accessible via the $_51d array. You could use  var_dump($_51d); to easily see all the properties and values available. See the PHP Guide for more information.

The paid for versions of the plugin contain more properties and features. Learn more .

51Degrees.mobi paid for device data can be distributed under licence with 3rd party skins or plugins. Please contact us for more information.



Disabling Redirection

To disable redirection (eg, to have a link to the desktop site) you will need to 'NO_SWITCH' to true:

									$SESSION['NO_SWITCH'] = true;

									

This needs to be set before the desktop page is loaded. Redirection can be re enabled by unset ting 'NO_SWITCH'.