Detect mobile browser for android and iphone..

Want to Use below code as in wordpress post

if(strstr($_SERVER['HTTP_USER_AGENT'],'Android')){

      echo '<img src="/images/android.png">';

      }
      else if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone'))
      {
          echo '<img src="/images/iphone.png">';
    }
    else {
         echo '<img src="/images/Download-now-button.png">';
        }

Hi,

As per my understanding you want to include above code to all posts / pages. is it correct?

I suggest you to create a small plugin and apply code to the footer. Below is the plugin code. Create a file i.e. "wp_plugin.php" and copy all code on it. Pleace "wp_plugin.php" in wp-contnet/plugin/"wp_plugin.php". Go to your Admin panel and actiate it. You can see your code at footer on Post or Page (Not in Admin)

<?php
/*
Plugin Name: Add code to footer (By Ajay)
Description: Add your custom code to Post / Page footer
Version: 0.1
Author: Ajay Gokhale
Author URI: http://www.facebook.com/Amilextech
License: GPL2
*/

function display_custom_code()
{
    //Get some blog info if you want to use 
    $bloginfo = get_bloginfo();
    $blog_name = get_bloginfo('name');  

    $theme_info = get_theme_info($blog_name);
    $output = '';
    // Your custom code
    $output .= 'Your custom code for footer';
    $output .= 'More Your custom code for footer';

    echo $output;
}

//Add to Footer
add_action('wp_footer', 'display_custom_code');

?>

Please check and let me know.
Thanks,
Ajay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.