Title: Need auto detect short code
Last modified: August 22, 2016

---

# Need auto detect short code

 *  Resolved [evolve36](https://wordpress.org/support/users/evolve36/)
 * (@evolve36)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/need-auto-detect-short-code/)
 * Hello,
    How can we auto detect the screen size so that it switches between the
   desktop and mobile versions of the plug-in on the fly? This is a must as the 
   mobile version is missing some elements when viewed on a larger screen and the
   desktop version doesn’t work on a small mobile device. Having the code to automatically
   switch between the two versions depending on the screen size would be an elegant
   solution.
 * Thanks much
 * [https://wordpress.org/plugins/appointment-calendar/](https://wordpress.org/plugins/appointment-calendar/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [abhishek](https://wordpress.org/support/users/abhipathak/)
 * (@abhipathak)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/need-auto-detect-short-code/#post-5515241)
 * Hello evolve36,
 * 1. go to in your plugin directory and open appointment-calendar.php file
    2. 
   search comment // Including Calendar Short-Code Page 3 after this comment past
   all this code
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       //require_once("appointment-calendar-shortcode.php");
       //require_once("appointment-calendar-mobile.php");
   
       add_shortcode( 'APCAL_AUTO_DETECT', 'apcal_detect_device' );
       function apcal_detect_device(){
   
       if(wp_is_mobile()){ //This is mobile
       // load required js css
       short_code_detect();
       include("appointment-calendar-mobile.php");
       //Calling Calendar Mobile Shortcode function
       appointment_calendar_short_code_mobile();
   
       } else { //This is desktop system
       // load required js css
       short_code_detect();
       include("appointment-calendar-shortcode.php");
       //Calling Calendar Short-Code function
       appointment_calendar_shortcode();
       }
       }
   
       4. go to in line number 131 or search function short_code_detect line
       and replace all function with this function code
   
       function short_code_detect() {
       global $wp_query;
       $posts = $wp_query->posts;
       $pattern = get_shortcode_regex();
       foreach ($posts as $post){
       if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
       && array_key_exists( 2, $matches )
       && in_array( 'APCAL_PC', $matches[2] ) || in_array( 'APCAL_MOBILE', $matches[2] ) || in_array( 'APCAL', $matches[2] ) || in_array('APCAL_AUTO_DETECT', $matches[2]) )
       {
       wp_register_script(
       'jquery-custom',
       plugins_url('menu-pages/fullcalendar-assets-new/js/jquery-ui-1.8.23.custom.min.js', __FILE__),
       array('jquery'),
       true
       );
       //wp_register_script( 'jquery-custom', plugins_url('menu-pages/fullcalendar-assets-new/js/jquery-ui-1.8.23.custom.min.js', __FILE__), array('jquery'), true);
       wp_enqueue_script('full-calendar',plugins_url('/menu-pages/fullcalendar-assets-new/js/fullcalendar.min.js', __FILE__),array('jquery','jquery-custom'));
       wp_enqueue_script('calendar',plugins_url('calendar/calendar.js', __FILE__));
       wp_enqueue_script('moment-min',plugins_url('calendar/moment.min.js', __FILE__));
       wp_enqueue_style('bootstrap-apcal',plugins_url('/menu-pages/bootstrap-assets/css/bootstrap-apcal.css', __FILE__));
       wp_enqueue_style('fullcalendar-css',plugins_url('/menu-pages/fullcalendar-assets-new/css/fullcalendar.css', __FILE__));
       wp_enqueue_style('datepicker-css',plugins_url('/menu-pages/datepicker-assets/css/jquery-ui-1.8.23.custom.css', __FILE__));
       break;
       }
       }
       }
       ```
   
 * now you have to use this short code [APCAL_AUTO_DETECT] on your page
    and you
   have to permission to access both devices with one short code
 * Thanks
 *  Thread Starter [evolve36](https://wordpress.org/support/users/evolve36/)
 * (@evolve36)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/need-auto-detect-short-code/#post-5515299)
 * Hi abhishek,
 * Thank you for your reply. I did make the changes you stated but the site will
   no longer load. When I switch back to the original “appointment-calendar.php”
   the site loads without issue.
 * Can you please let me know what you meant by this:
 * “you have to permission to access both devices with one short code”
 * Do I need to change permission settings somewhere?
 * Thanks
 *  Thread Starter [evolve36](https://wordpress.org/support/users/evolve36/)
 * (@evolve36)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/need-auto-detect-short-code/#post-5515301)
 * Hi abhishek,
    Please ignore my previous comment, I was able to get the issue 
   resolved. The problem was due to the cut+paste of the above code not getting 
   copied over correctly.
 * The site and this feature is now working as expected now. I would highly recommend
   that this gets added as a standard feature of the plug-in in the next update.
 * Thank you again for the quick reply.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Need auto detect short code’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/appointment-calendar.svg)
 * [Appointment Calendar](https://wordpress.org/plugins/appointment-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/appointment-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/appointment-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/appointment-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/appointment-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/appointment-calendar/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [evolve36](https://wordpress.org/support/users/evolve36/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/need-auto-detect-short-code/#post-5515301)
 * Status: resolved