Theme Switcha Shortcodes

Below, you’ll find a detailed guide on how to add the Theme Switcha Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Theme Switcha Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Theme Switcha Plugin and the shortcodes it provides:

Plugin Icon
Theme Switcha – Easily Switch Themes for Development and Testing

"Theme Switcha is a WordPress plugin designed for easy switching of themes during development and testing. This plugin ensures smooth transitions and accurate test environments."

★★★★✩ (56) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: 5.6.20
Included Shortcodes:
  • [theme_switcha_thumbs]
  • [theme_switcha_list]
  • [theme_switcha_select]
  • [theme_switcha_link]

Theme Switcha [theme_switcha_thumbs] Shortcode

The Theme Switcha shortcode is a WordPress plugin that dynamically displays thumbnails. This shortcode uses the ‘theme_switcha_display_thumbs’ function to extract the style attribute and outputs the thumbnails accordingly. If the style is set to ‘true’, it adds frontend thumb styles to the output.

Shortcode: [theme_switcha_thumbs]

Parameters

Here is a list of all possible theme_switcha_thumbs shortcode parameters and attributes:

  • style – Determines if frontend thumbnail styles are applied

Examples and Usage

Basic example – A simple usage of the ‘theme_switcha_thumbs’ shortcode, it will display the theme switcher thumbnails with default styles.

[theme_switcha_thumbs /]

Advanced examples

Displaying the theme switcher thumbnails without any styles. By setting the ‘style’ parameter to ‘false’, the thumbnails will be displayed without any additional styling.

[theme_switcha_thumbs style=false /]

Creating a shortcode with multiple parameters. This example shows how to create a shortcode with more than one parameter. It’s important to note that the ‘style’ parameter is set to ‘true’, which means the thumbnails will be displayed with additional styling.

[theme_switcha_thumbs style=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [theme_switcha_thumbs] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('theme_switcha_thumbs', 'theme_switcha_display_thumbs_shortcode');

Shortcode PHP function:

function theme_switcha_display_thumbs_shortcode($attr, $content = null) {
	
	extract(shortcode_atts(array(
		'style'  => 'true',
	), $attr));
	
	$output = theme_switcha_display_thumbs();
	
	if ($style === 'true') {
		
		$styles = theme_switcha_frontend_thumb_styles();
		
		$output = $styles . $output;
		
	}
	
	return $output;
	
}

Code file location:

theme-switcha/theme-switcha/inc/plugin-core.php

Theme Switcha [theme_switcha_list] Shortcode

The Theme Switcha shortcode is designed to display a list of themes. . It lets you control the display style and whether to include frontend styles. The ‘display’ attribute determines the list type, while the ‘style’ attribute decides if frontend styles are applied.

Shortcode: [theme_switcha_list]

Parameters

Here is a list of all possible theme_switcha_list shortcode parameters and attributes:

  • display – defines the format of the theme switcher list
  • style – determines if the frontend styles are applied to the list

Examples and Usage

Basic example – Displaying a theme list with default styling

[theme_switcha_list]

Advanced examples

Displaying a theme list without any styling. This can be useful if you want to apply your own custom styles to the theme list.

[theme_switcha_list style="false"]

Displaying a theme list in a grid format. This can be useful if you want to display multiple themes in a more visually appealing way.

[theme_switcha_list display="grid"]

Combining both parameters to display a theme list in a grid format without any styling. This gives you the most control over the appearance of your theme list.

[theme_switcha_list display="grid" style="false"]

PHP Function Code

In case you have difficulties debugging what causing issues with [theme_switcha_list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('theme_switcha_list', 'theme_switcha_display_list_shortcode');

Shortcode PHP function:

function theme_switcha_display_list_shortcode($attr, $content = null) {
	
	extract(shortcode_atts(array(
		'display' => 'list',
		'style'   => 'true',
	), $attr));
	
	$output = theme_switcha_display_list($display);
	
	if ($style === 'true') {
		
		$styles = theme_switcha_frontend_list_styles($display);
		
		$output = $styles . $output;
		
	}
	
	return $output;
	
}

Code file location:

theme-switcha/theme-switcha/inc/plugin-core.php

Theme Switcha [theme_switcha_select] Shortcode

The Theme Switcha shortcode is a tool that displays a dropdown menu for theme selection. It allows users to switch between different themes on the WordPress site. This shortcode operates by calling the function ‘theme_switcha_display_dropdown_shortcode’. The function extracts the ‘text’ attribute from the shortcode to customize the dropdown menu’s prompt message. By default, the prompt text is ‘Choose a theme..’. The function then calls ‘theme_switcha_display_dropdown’ to generate the dropdown menu, which is returned as the output.

Shortcode: [theme_switcha_select]

Parameters

Here is a list of all possible theme_switcha_select shortcode parameters and attributes:

  • text – defines the placeholder text in the theme selection dropdown

Examples and Usage

Basic example – Utilize the shortcode to display a dropdown menu with the default text ‘Choose a theme..’

[theme_switcha_select /]

PHP Function Code

In case you have difficulties debugging what causing issues with [theme_switcha_select] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('theme_switcha_select', 'theme_switcha_display_dropdown_shortcode');

Shortcode PHP function:

function theme_switcha_display_dropdown_shortcode($attr, $content = null) {
	
	extract(shortcode_atts(array(
		'text' => 'Choose a theme..',
	), $attr));
	
	$output = theme_switcha_display_dropdown($text);
	
	return $output;
	
}

Code file location:

theme-switcha/theme-switcha/inc/plugin-core.php

Theme Switcha [theme_switcha_link] Shortcode

The ‘theme_switcha_link’ shortcode is used to display a clickable link that switches the website’s theme. It extracts the ‘theme’ and ‘text’ attributes from the shortcode, then creates a URL with these parameters. The URL points to the current page but with the specified theme activated. The ‘text’ attribute is used as the link’s label.

Shortcode: [theme_switcha_link]

Parameters

Here is a list of all possible theme_switcha_link shortcode parameters and attributes:

  • theme – Specifies the theme to be switched to
  • text – Defines the display text for the theme switch link

Examples and Usage

Basic example – A simple usage of the shortcode to switch to the active theme with the default text link ‘Switch Theme’.

[theme_switcha_link /]

Advanced examples

Using the shortcode to switch to a specific theme by providing the theme name. In this case, the theme name is ‘twentytwenty’.

[theme_switcha_link theme='twentytwenty' /]

Using the shortcode to switch to a specific theme and customizing the text link. Here, the theme name is ‘twentytwenty’ and the text link is ‘Change to Twenty Twenty’.

[theme_switcha_link theme='twentytwenty' text='Change to Twenty Twenty' /]

Using the shortcode to switch to the active theme with a customized text link. In this case, the text link is ‘Change Theme’.

[theme_switcha_link text='Change Theme' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [theme_switcha_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('theme_switcha_link', 'theme_switcha_display_text_link');

Shortcode PHP function:

function theme_switcha_display_text_link($attr, $content = null) {
	
	global $theme_switcha_options;
	
	$options = $theme_switcha_options;
	
	$passkey = isset($options['passkey']) ? $options['passkey'] : null;
	
	$protocol = is_ssl() ? 'https://' : 'http://';
	
	$base_url = esc_url_raw($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
	
	if (strpos($base_url, '/wp-admin/') !== false) $base_url = get_home_url();
	
	extract(shortcode_atts(array('theme' => theme_switcha_active_theme(), 'text' => 'Switch Theme'), $attr));
	
	$params = array('theme-switch' => $theme, 'passkey' => $passkey);
	
	$href = add_query_arg($params, $base_url);
	
	$output = '<a href="'. esc_url($href) .'">'. esc_html($text) .'</a>';
	
	return $output;
	
}

Code file location:

theme-switcha/theme-switcha/inc/plugin-core.php

Conclusion

Now that you’ve learned how to embed the Theme Switcha Plugin shortcodes, 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *