Skip to content

Instantly share code, notes, and snippets.

@grappler
Last active December 21, 2015 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grappler/6336435 to your computer and use it in GitHub Desktop.
Save grappler/6336435 to your computer and use it in GitHub Desktop.
This short plugin allows users to display content according to the device the page is being viewed on.
<?php
/**
*
* @package Adaptive Shortcode
* @author Ulrich Pogson <grapplerulrich@gmail.com>
* @license GPL-2.0+
* @link http://ulrich.pogson.ch
* @copyright 2013 Ulrich Pogson
*
* @wordpress-plugin
* Plugin Name: Adaptive Shortcode
* Plugin URI: https://gist.github.com/grappler/6336435
* Description: This short plugin allows users to display content according to the device the page is being viewed on.
* Version: 1.0.0
* Author: Ulrich Pogson
* Author URI: http://ulrich.pogson.ch
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
/**
* Add Shortcode for mobile content
*
* @example [is_mobile][/is_mobile]
*/
function is_mobile_shortcode( $atts , $content = null ) {
if ( wp_is_mobile() ) {
return do_shortcode( $content );
}
}
add_shortcode( 'is_mobile', 'is_mobile_shortcode' );
/**
* Add Shortcode for desktop content
*
* @example [is_desktop][/is_desktop]
*/
function is_desktop_shortcode( $atts , $content = null ) {
if ( ! wp_is_mobile() ) {
return do_shortcode( $content );
}
}
add_shortcode( 'is_desktop', 'is_desktop_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment