Below, you’ll find a detailed guide on how to add the Any Mobile Theme Switcher Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Any Mobile Theme Switcher Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Any Mobile Theme Switcher Plugin and the shortcodes it provides:
Any Mobile Theme Switcher [show_theme_switch_link] Shortcode
The Any Mobile Theme Switcher shortcode allows users to switch between desktop and mobile themes. This shortcode checks the currently displayed theme. If a mobile theme is active, it shows a link to switch to the desktop theme. Conversely, if the desktop theme is active, it shows a link to switch to the mobile theme. This functionality enhances user experience by providing theme flexibility.
Shortcode: [show_theme_switch_link]
Examples and Usage
Basic example – A simple usage of the shortcode to switch between mobile and desktop themes.
[show_theme_switch_link /]
Advanced examples:
Using the shortcode to switch to the desktop theme. In this example, the ‘amts_force_param’ is set to ‘desktop’ which forces the switch to the desktop theme.
[show_theme_switch_link amts_force_param="desktop" /]
Using the shortcode to switch to the mobile theme. Similar to the previous example, but this time the ‘amts_force_param’ is set to ‘mobile’, which forces the switch to the mobile theme.
[show_theme_switch_link amts_force_param="mobile" /]
Using the shortcode to switch to the desktop theme but with a custom link text. The ‘desktop_view_theme_link_text’ attribute is used to specify the text that will be displayed on the switch link.
[show_theme_switch_link amts_force_param="desktop" desktop_view_theme_link_text="Switch to Desktop View" /]
Using the shortcode to switch to the mobile theme with a custom link text. Similar to the previous example, but this time the ‘mobile_view_theme_link_text’ attribute is used to specify the text that will be displayed on the switch link.
[show_theme_switch_link amts_force_param="mobile" mobile_view_theme_link_text="Switch to Mobile View" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [show_theme_switch_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('show_theme_switch_link', 'show_theme_switch_link_func');
Shortcode PHP function:
function show_theme_switch_link_func( $atts ){
global $amts_shown_theme;
global $amts_status;
global $amts_force_param;
$desktopSwitchLink = get_option('show_switch_link_for_desktop');
if ($amts_shown_theme){
$return = '<a rel="external" data-ajax="false" href="'.get_bloginfo('url').'?'.$amts_force_param.'=desktop" class="am-switch-btn godesktop">'.get_option('desktop_view_theme_link_text').'</a>';
} else {
if ((!empty($amts_status)) || ($desktopSwitchLink == 'yes')){
$return = '<a href="'.get_bloginfo('url').'?'.$amts_force_param.'=mobile" class="am-switch-btn gomobile">'.get_option('mobile_view_theme_link_text').'</a>';
}
}
return $return;
}
Code file location:
any-mobile-theme-switcher/any-mobile-theme-switcher/any-mobile-theme-switcher.php
Conclusion
Now that you’ve learned how to embed the Any Mobile Theme Switcher Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply