WordPress.org

Ready to get started?Download WordPress

Forums

Best way to: run regular theme and shortcodes + mobile theme in tandem (3 posts)

  1. red.rover
    Member
    Posted 2 years ago #

    I'm currently using one main theme for my WP install, that has a number of handy shortcodes and customisation options. It presents very well.

    I installed a mobile theme, and added a plugin to detect for mobiles and present that theme instead.

    But the problem of course is that the content in the main theme has shortcodes and pages with sidebar navigation that doesn't play well with the mobile theme. The shortcodes show up as simply text.

    I'm not sure the best way to fix this. I have considered simply making mobile-specific pages and a mobile-specific menu, but that becomes an SEO issue because you're doubling up on content. And it means mobile users visiting a regular link will have problems. The same can be said for making a m.mysite.com subdomain for it.

    In Drupal page elements are coded into the template files, and you can print out simply the body text and the body pictures separate to the rest. One solution could be to use this (unideal) method, and hard code a front page design and others?

    Can anyone tell me their solution to this?

  2. aaronp5
    Member
    Posted 2 years ago #

    Hello,
    I've also run into the same problem. I tried some codes in the functions.php of the mobile template to remove shortcodes, which does remove them- but the content that is wrapped in the shortcode is also removed. Would love any suggestions on this. thanks!

  3. aaronp5
    Member
    Posted 2 years ago #

    Just figured it out, i copied the code from the plugin (strip non registered shortcodes) into my mobile themes function.php file. worked like a charm. remvoes the codes while leaving the content.

    function strip_nonscodes($text){
    
        global $shortcode_tags;
    
        if(!(empty($shortcode_tags) || !is_array($shortcode_tags))){                    
    
            $exclude_codes = join( '|', array_map('preg_quote', array_keys($shortcode_tags)));           
    
            $text = preg_replace("/\[(?!(".$exclude_codes."))(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s",'', $text);  #strip shortcode
        }
    
        return $text;
    }
    add_filter('the_content','strip_nonscodes');

Topic Closed

This topic has been closed to new replies.

About this Topic