Content Switcher

Content Switcher allows you to easily insert into posts, pages and widgets of your website random numbers, and random or variable contents. You can use it, for example, to display COOKIE, ENV, GET, GLOBALS, POST, REQUEST, SERVER or SESSION variables. Content Switcher also allows you to optimize your website with Google Optimize and to add the Google Analytics tracking code to each page of your website.

Download Content Switcher for free

Summary

  1. Installation
  2. Upgrade
  3. Random Numbers [+]
    1. Random Numbers Between Two Numbers
    2. Random Numbers In A Set
    3. Display Of Random Numbers
    4. The filter Attribute
  4. Random Contents [+]
    1. The filter Attribute
    2. Multiple Display Of A String Of Characters
  5. Variables [+]
    1. The default Attribute
    2. The filter Attribute
  6. Variable Contents [+]
    1. The filter Attribute
    2. Name Of The Variable
    3. Values Of The Variable
    4. Display Of A Variable
  7. Google
  8. Display Of The Options [+]
    1. The default Attribute
    2. The filter Attribute
  9. Advanced Customization [+]
    1. Custom Files
    2. Custom Languages
  10. FAQ [+]
    1. Why does Google Optimize not work on my website?
    2. How can I use cotillions in my WordPress theme?
    3. How can I use cotillions in comments?
    4. How can I use cotillions in attributes of cotillions?
    5. How can I nest several identical cotillions?

1. Installation

You can install Content Switcher through the Add Plugins page of the Plugins menu in WordPress (Plugins => Add New => Upload Plugin). Upload the plugin file without unzipping it. You can also install it like this:

  1. Unzip the plugin file.
  2. Upload with your FTP software the content-switcher folder, and only this folder, to your plugins directory (it should be wp-content/plugins).

Once you have installed Content Switcher:

  1. Activate the plugin through the Plugins menu in WordPress.
  2. Configure the plugin through the Content Switcher options page in WordPress.

2. Upgrade

When you upgrade Content Switcher, you don't lose any settings or any data.

You can upgrade Content Switcher through the Plugins menu in WordPress, and through the WordPress Updates page of the Dashboard menu in WordPress (Dashboard => Updates), or through the Add Plugins page of the Plugins menu in WordPress (Plugins => Add New => Upload Plugin, upload the plugin file without unzipping it). You can also upgrade it like this:

  1. Unzip the plugin file.
  2. Upload with your FTP software the content-switcher folder, and only this folder, to your plugins directory (it should be wp-content/plugins), without deleting the content-switcher folder that already exists in this directory.

You don't need to deactivate and reactivate the plugin.

3. Random Numbers

3.1 Random Numbers Between Two Numbers

To display a random number between 0 and M, insert into your posts/pages/widgets a cotillion like this:

[random-number max=M]

Example (random number between 0 and 5):

[random-number max=5]

Result (with a little formatting):

4

To display a random number between m and M (m and M relative integers), insert into your posts/pages/widgets a cotillion like this:

[random-number min=m max=M]

Example (random number between -3 and 8):

[random-number min=-3 max=8]

Result (with a little formatting):

7

3.2 Random Numbers In A Set

To display a random number belonging to a set, insert into your posts/pages/widgets a cotillion like this:

[random-number set=a/b/c/…]

Example (random number belonging to { 34; 5; -3; 8; -21 }):

[random-number set=34/5/-3/8/-21]

Result (with a little formatting):

5

3.3 Display Of Random Numbers

You can use the digits attribute to display a random number with at least d digits:

[random-number min=m max=M digits=d]

Example (random number between 0 and 144, displayed with at least 3 digits):

[random-number max=144 digits=3]

Result (with a little formatting):

144

Other example (random image taken from the short film Big Buck Bunny):

<img src="/medias/images/big-buck-bunny/screenshots/[random-number min=1 max=30 digits=2].webp" alt="Random image taken from the short film Big Buck Bunny" title="Random image taken from the short film Big Buck Bunny" />

Result:

Random image taken from the short film Big Buck Bunny
Copyright © Blender Foundation | Peach.Blender.org

3.4 The filter Attribute

You can specify a PHP function that will be applied to the number before this one is displayed, using the filter attribute, like this:

[random-number min=m max=M filter=function]

Replace function by the name of the function you want to apply.

It is possible to specify several functions for the filter attribute, by separating the different functions by /, like this:

[random-number min=m max=M  filter=function1/function2/…/functionN]

The functions will be applied in the specified order.

4. Random Contents

To display a random content, insert into your posts/pages/widgets a cotillion like this:

[random-content]
First random content[other]
Second random content[other]
Third random content[other]

[/random-content]

Example:

[random-content]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/random-content]

Result (with a little formatting):

And the dreams that you dare to dream, really do come true

4.1 The filter Attribute

You can specify a PHP function that will be applied to the content before this one is displayed, using the filter attribute, like this:

[random-content filter=function]
Content 1[other]Content 2[other]…[other]Content K[/random-content]

Replace function by the name of the function you want to apply.

It is possible to specify several functions for the filter attribute, by separating the different functions by /, like this:

[random-content filter=function1/function2/…/functionN]
Content 1[other]Content 2[other]…[other]Content K[/random-content]

The functions will be applied in the specified order.

4.2 Multiple Display Of A String Of Characters

It's possible to display several times the same (random or not random) string of characters, using the string attribute. You can specify any string of characters for this attribute, including cotillions, provided to replace [ by ( and ] by ). And don't forget to include the quotes at the beginning and the end of the string:

[random-content string="(random-content)First random string(other)Second random string(other)Third random string(other)(/random-content)"]
[string][string][string][/random-content]

The [string] cotillion displays the string of characters. The default (defined here) and filter (defined here) attributes are available for this cotillion.

Example (random image taken from the short film Big Buck Bunny):

[random-content string="(random-number min=1 max=30 digits=2)"]
<a href="/medias/images/big-buck-bunny/screenshots/[string].webp"><img src="/medias/images/big-buck-bunny/screenshots/320/[string].webp" alt="Random image taken from the short film Big Buck Bunny" title="Random image taken from the short film Big Buck Bunny" /></a>
[/random-content]

Result (with a little formatting):

Random image taken from the short film Big Buck Bunny
Copyright © Blender Foundation | Peach.Blender.org

5. Variables

To display a COOKIE, ENV, GET, GLOBALS, POST, REQUEST, SERVER or SESSION variable, insert into your posts/pages/widgets a cotillion like this:

[variable-string type=type name=name]

The type attribute can be equal to cookie, env, get, globals, post, request, server or session. Its default value is get. The name attribute is the name of the variable.

Example:

Your IP address is [variable-string type=server name=REMOTE_ADDR].

Résultat:

Your IP address is 44.192.107.255.

5.1 The default Attribute

You can specify a text that will be displayed instead of the variable when this one is empty, using the default attribute, like this:

[variable-string type=type name=name default="text"]

Don't forget to include the quotes at the beginning and the end of the default value.

5.2 The filter Attribute

You can specify a PHP function that will be applied to the variable before this one is displayed, using the filter attribute, like this:

[variable-string type=type name=name filter=function]

Replace function by the name of the function you want to apply.

It is possible to specify several functions for the filter attribute, by separating the different functions by /, like this:

[variable-string type=type name=name filter=function1/function2/…/functionN]

The functions will be applied in the specified order.

6. Variable Contents

To display a variable content, insert into your posts/pages/widgets a cotillion like this:

[variable-content]
Default content[other]
First alternate content[other]
Second alternate content[other]

[/variable-content]

The displayed content is not random but is determined by the URL of the page.

Pages displaying the default content:

https://www.kleor.com/content-switcher/en/

https://www.kleor.com/content-switcher/en/?content=0

Page displaying the first alternate content:

https://www.kleor.com/content-switcher/en/?content=1

Page displaying the second alternate content:

https://www.kleor.com/content-switcher/en/?content=2

This is the value of the content variable of the URL that determines the displayed content. If its value:

Example:

[variable-content]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]

Result (with a little formatting):

Somewhere over the rainbow, way up high

Pages displaying the default content:

https://www.kleor.com/content-switcher/en/

https://www.kleor.com/content-switcher/en/?content=0

Page displaying the first alternate content:

https://www.kleor.com/content-switcher/en/?content=1

Page displaying the second alternate content:

https://www.kleor.com/content-switcher/en/?content=2

Page displaying the third alternate content:

https://www.kleor.com/content-switcher/en/?content=3

If you don't want to use a GET variable to display the variable content, you can also do the same thing with a COOKIE, ENV, GLOBALS, POST, REQUEST, SERVER or SESSION variable using the type attribute.

6.1 The filter Attribute

You can specify a PHP function that will be applied to the content before this one is displayed, using the filter attribute, like this:

[variable-content filter=function]
Content 1[other]Content 2[other]…[other]Content K[/variable-content]

Replace function by the name of the function you want to apply.

It is possible to specify several functions for the filter attribute, by separating the different functions by /, like this:

[variable-content filter=function1/function2/…/functionN]
Content 1[other]Content 2[other]…[other]Content K[/variable-content]

The functions will be applied in the specified order.

6.2 Name Of The Variable

You can specify a name different than content for the variable using the name attribute:

Example:

[variable-content name=lyric]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]

Result (with a little formatting):

Somewhere over the rainbow, way up high

Pages displaying the default content:

https://www.kleor.com/content-switcher/en/

https://www.kleor.com/content-switcher/en/?lyric=0

Page displaying the first alternate content:

https://www.kleor.com/content-switcher/en/?lyric=1

Page displaying the second alternate content:

https://www.kleor.com/content-switcher/en/?lyric=2

Page displaying the third alternate content:

https://www.kleor.com/content-switcher/en/?lyric=3

6.3 Values Of The Variable

You can specify values different than numbers for the variable using the values attribute.

Example:

[variable-content name=lyric values=first/second/third/fourth]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]

Result (with a little formatting):

Somewhere over the rainbow, way up high

Pages displaying the first lyric:

https://www.kleor.com/content-switcher/en/

https://www.kleor.com/content-switcher/en/?lyric=first

Page displaying the second lyric:

https://www.kleor.com/content-switcher/en/?lyric=second

Page displaying the third lyric:

https://www.kleor.com/content-switcher/en/?lyric=third

Page displaying the fourth lyric:

https://www.kleor.com/content-switcher/en/?lyric=fourth

6.4 Display Of A Variable

You can display the value of the variable. To do this, simply use only the default content without specifying any alternate content. If the value of the variable is not specified in the URL, the default content will be displayed:

[variable-content name=name]Default content[/variable-content]

Example:

Welcome [variable-content name=first-name]to You[/variable-content]!

Result:

Welcome to You!

Page displaying your first name:

https://www.kleor.com/content-switcher/en/?first-name=your-first-name

7. Google

If you have a Google Analytics account, you can analyze the traffic of your website by completing the Tracking ID of your Google Analytics account field. The Google Analytics tracking code will not be added to the pages of your website before this. Your tracking ID is mentioned on your Google Analytics dashboard.

If you also have a Google Optimize account, you can optimize your website by completing the Container ID of your Google Optimize account field. The Google Optimize tracking code will not be added to the pages of your website before this. Your container ID is mentioned on your Google Optimize dashboard.

8. Display Of The Options

To display an option of Content Switcher, insert into your posts/pages/widgets a cotillion like this:

[content-switcher option]

by replacing option with:

Example:

Tracking ID of my Google Analytics account: [content-switcher analytics-tracking-id]

Result:

Tracking ID of my Google Analytics account: UA-16184215-1

8.1 The default Attribute

You can specify a text that will be displayed instead of the option when this one is empty, using the default attribute, like this:

[content-switcher option default="text"]

Don't forget to include the quotes at the beginning and the end of the default value.

8.2 The filter Attribute

You can specify a PHP function that will be applied to the option before this one is displayed, using the filter attribute, like this:

[content-switcher option filter=function]

Replace function by the name of the function you want to apply.

Sometimes, the option is an English word. You can translate it into the language of your website by entering i18n as the value for the filter attribute.

Example:

JavaScript enabled: [content-switcher javascript-enabled filter=i18n]

Result:

JavaScript enabled: no

It is possible to specify several functions for the filter attribute, by separating the different functions by /, like this:

[content-switcher option filter=function1/function2/…/functionN]

The functions will be applied in the specified order.

9. Advanced Customization

9.1 Custom Files

You can replace all Content Switcher files (except content-switcher.php) with your own files. For this, create the content-switcher-custom-files folder in the plugins directory (the one where you installed Content Switcher) of your website.

For example, if you want to replace the includes/data.php file of Content Switcher with a file you have customized, create the includes folder in the content-switcher-custom-files folder, and upload your data.php file to this folder.

You can set yourself the directory where your custom files are stored, by inserting this line:

define('CONTENT_SWITCHER_CUSTOM_FILES_PATH', ABSPATH.'custom-files/content-switcher/');

just after:

if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

in your wp-config.php file.

Replace custom-files/content-switcher with what you want. The value of CONTENT_SWITCHER_CUSTOM_FILES_PATH must end with a /.

9.2 Custom Languages

Content Switcher is developed in English and contains files that translate it in French. If you wish, you can translate it into another language.

To do this, create your custom files directory by following these guidelines. Create the languages folder inside of it, and upload your translation files to this folder.

You can create your translation files with the languages/content-switcher.pot file of the plugin, and by using the free software Poedit. Your MO and PO translation files must be named like this:

content-switcher-ll_CC.mo
content-switcher-ll_CC.po

ll_CC is the value displayed by this line of cotillion:

echo get_locale();

when it's executed in one of the files of your WordPress website.

10. FAQ

10.1 Why does Google Optimize not work on my website?

Check the Add JavaScript code field in the options page of Content Switcher. Check also the Container ID of your Google Optimize account field in the same page. Check the header.php file of your WordPress theme. Make sure that it contains a call to wp_head.

10.2 How can I use cotillions in my WordPress theme?

Insert into the PHP files of your theme a cotillion like this:

<?php echo do_shortcode('[your-cotillion]'); ?>

10.3 How can I use cotillions in comments?

Edit the functions.php file (create it if it doesn't exist) of your WordPress theme and add this line of cotillion:

add_filter('comment_text', 'do_shortcode');

10.4 How can I use cotillions in attributes of cotillions?

You can use cotillions in most attributes of Content Switcher cotillions, provided to replace [ by ( and ] by ), like this:

[your-cotillion attribute='(your-other-cotillion)']

Don't forget to include the quotes at the beginning and the end of the cotillion.

10.5 How can I nest several identical cotillions?

When you nest several identical cotillions, you must add an integer between 1 and 3 at the end of the tags of these cotillions, like this:

[variable-content…]…
[variable-content1…]…
[variable-content2…]…
[variable-content3…]…
[/variable-content3]…
[/variable-content2]…
[/variable-content1]…
[/variable-content]

Translators