Support » Plugins » Hacks » Override shortcode for mobile theme?

  • Hi guys. I have a site that has an alternative theme for mobile devices.

    There are several shortcodes that the site uses to embed youtube videos, Google Maps etc. When the mobile theme is in use, I would like to override these shortcodes to simply display a link to the content, rather than embedding the content itself. Any tips on doing this?

    Many thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I would try using remove_shortcode in the mobile theme’s functions.php.

    [silly and oversimplified] example

    function newGoogleVideoShortcode($atts) {
    add_shortcode('google_video', 'newGoogleVideoShortcode');

    As long as it’s in the mobile theme’s functions file, it should only remove those codes when the mobile theme is in use.

    Thanks this worked great. I found I was able to override the shortcode just by using add_shortcode(), no need to remove it first.

    I had a problem with one plugin (Viper’s Video Shortcodes) where this method didn’t work. I got round it by using an alternative plugin.



    Hi, I have a similar problem and wondering if either of you can help.
    I have a mobile theme (carrington) that shows the shortcodes coding of the regular site, i’d simply like it hidden or ignored. in fact the site does ignore it but shows the code so how can i hide it?
    Please spell it out for a non-techie!
    many thank in advance.
    V. x



    Hi bitsyandkitty.

    All you need to do is register the shortcode you wish to hide in the functions.php of your mobile theme.

    Here’s a very simple example:

    function my_shortcode_handler( $atts, $content=null, $code="" )
            return '';
        //override the 'testimonial' shortcode
        add_shortcode( 'testimonial', 'my_shortcode_handler' );



    Hi Miraclemaker- that is fab – thanks so much. a very handy piece of code for rest of 2012 no doubt! x

    I’m quite possibly being a moron, but I’ve tried miraclemaker’s code above several times now, and get a fatal error every time. Are there some parameters for where this should go that I’m missing?

    Background: I’m trying desperately to mobilize a theme from Elegant Themes using their theme/plugin Handheld. The problem is that shortcodes on the main site are removed in the mobile version, which also removes the content inside them. I made a change to handheld.php which made the content visible, but now it’s wrapped in visible shortcode text, which I need to get rid of.

    I tried the above code, edited to reference two of Elegant Themes’ shortcodes ([dropcap] and [one_third]), but both times the plugin was deactivated with a fatal error.


    function my_shortcode_handler( $atts, $content=null, $code=”” )
    return ”;

    //override the ‘dropcap’ shortcode
    add_shortcode( ‘dropcap’, ‘my_shortcode_handler’ );

    Any idea what I’m doing wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Override shortcode for mobile theme?’ is closed to new replies.