Content Switcher

Content Switcher is a free WordPress plugin allowing 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 Optimizer and to add the Google Analytics code to each page of your website.

WordPress Download

Summary

  1. Installation
  2. Upgrade
  3. Random Numbers
  4. Random Contents
  5. Variables
  6. Variable Contents
  7. Google Optimizer
  8. Display Of The Options
  9. FAQ

1. Installation

  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).
  3. Activate the plugin through the Plugins menu in WordPress.
  4. Configure the plugin through the Content Switcher options page in WordPress.

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

2. Upgrade

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

  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.

You can also upgrade Content Switcher through the Plugins menu in WordPress, and through the Updates page of the Dashboard menu in WordPress (Dashboard => Updates).

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 code like this:

[random-number max=M]

Example (random number between 0 and 5):

[random-number max=5]

Result (with a little formatting):

1

To display a random number between m and M (m and M relative integers), insert into your posts/pages/widgets a code 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):

8

3.2 Random Numbers In A Set

To display a random number belonging to a set, insert into your posts/pages/widgets a code 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):

092

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].jpg" 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 | www.BigBuckBunny.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 code 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):

Somewhere over the rainbow, skies are blue

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 shortcodes, 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] shortcode displays the string of characters. The default (defined here) and filter (defined here) attributes are available for this shortcode.

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

[random-content string="(random-number min=1 max=30 digits=2)"]
<a rel="[shadowbox]" href="/medias/images/big-buck-bunny/screenshots/[string].jpg"><img src="/medias/images/big-buck-bunny/screenshots/320/[string].jpg" 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 | www.BigBuckBunny.org

5. Variables

To display a COOKIE, ENV, GET, GLOBALS, POST, REQUEST, SERVER or SESSION variable, insert into your posts/pages/widgets a code 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 54.237.98.229.

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 code 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:

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

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

Page displaying the first alternate content:

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

Page displaying the second alternate content:

http://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:

  • is equal to 0 or is not specified, then the displayed content is the default content
  • is equal to 1, then the displayed content is the first alternate content
  • is equal to 2, then the displayed content is the second alternate content
  • ...

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:

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

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

Page displaying the first alternate content:

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

Page displaying the second alternate content:

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

Page displaying the third alternate content:

http://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:

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

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

Page displaying the first alternate content:

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

Page displaying the second alternate content:

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

Page displaying the third alternate content:

http://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:

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

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

Page displaying the second lyric:

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

Page displaying the third lyric:

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

Page displaying the fourth lyric:

http://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:

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

7. Google Optimizer

7.1 Creation Of Your Multivariate Experiment

To use Google Optimizer, you must have an account. Sign up for one if you do not. Through the website of Google Optimizer, create a new experiment.

Types of experiments
Types of experiments

A multivariate experiment allows you to test several items, but it also allows you to test only one item, as an A/B experiment. Click on Multivariate Experiment:

New multivariate experiment
New multivariate experiment

Check the I've completed the steps above and I'm ready to start setting up my experiment box and click on Create. You will arrive on this page:

New multivariate experiment - Step 1
New multivariate experiment - Step 1

Enter a name for your experiment, enter the address of your test page, the address of your conversion page, and click on Continue.

New multivariate experiment - Step 2
New multivariate experiment - Step 2

Select You will install and validate the JavaScript tags, and click on Continue. You will arrive on a page where you can get your control, tracking, and conversion scripts:

Control, tracking and conversion scripts
Control, tracking and conversion scripts

7.2 Configuration Of Your Tracking ID

You will find your tracking ID in your tracking script. It's a string of characters that starts with UA:

var gwoTracker=_gat._getTracker("UA-XXXXXXXX-X");

Enter your tracking ID in the Google Optimizer Account Tracking ID field in the options page of Content Switcher, check the Add JavaScript code box and click on Save Changes.

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

7.3 Configuration Of Your Test Page

For your test page, create the optimizer (in lowercase letters) custom field and enter the string starting with / and ending with /test in your tracking script:

gwoTracker._trackPageview("/XXXXXXXXXX/test");

Insert into the content of your test page at least a code like this:

[optimizer-content name="Name of your content"]
Your original content[/optimizer-content]

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

Example:

[optimizer-content name="Title"]<h1>Content Switcher</h1>[/optimizer-content]

7.4 Configuration Of Your Conversion Page

For your conversion page, create the optimizer (in lowercase letters) custom field and enter the string starting with / and ending with /goal in your conversion script:

gwoTracker._trackPageview("/XXXXXXXXXX/goal");

7.5 Finalization Of Your Multivariate Experiment

When you have configured your tracking ID, your test page and your conversion page as shown above, click on Validate pages. Google Optimizer will detect your control, tracking and conversion scripts. Click on Continue. You will arrive on a page where you will can complete your experiment by creating your different variations.

8. Display Of The Options

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

[content-switcher option]

by replacing option with:

  • admin-tracked to display the tracking of the administrators of your website by Google Analytics (possible values: yes, no)
  • analytics-tracking-id to display the tracking ID of your Google Analytics account
  • author-tracked to display the tracking of the authors of your website by Google Analytics (possible values: yes, no)
  • back-office-tracked to display the tracking of the back office pages of your website by Google Analytics (possible values: yes, no)
  • contributor-tracked to display the tracking of the contributors of your website by Google Analytics (possible values: yes, no)
  • editor-tracked to display the tracking of the editors of your website by Google Analytics (possible values: yes, no)
  • front-office-tracked to display the tracking of the front office pages of your website by Google Analytics (possible values: yes, no)
  • javascript-enabled to display the activation of JavaScript (possible values: yes, no)
  • optimizer-tracking-id to display the tracking ID of your Google Optimizer account
  • subscriber-tracked to display the tracking of the subscribers of your website by Google Analytics (possible values: yes, no)
  • version to display the version of Content Switcher
  • visitor-tracked to display the tracking of the visitors without any role of your website by Google Analytics (possible values: yes, no)

Example:

Google Analytics Account Tracking ID: [content-switcher analytics-tracking-id]

Result:

Google Analytics Account Tracking ID: 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: yes

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. FAQ

9.1 Why does Google Optimizer not work on my website?

Check the Add JavaScript code field in the options page of Content Switcher. Check also the Google Optimizer Account Tracking ID field in the same page. Check the header.php and footer.php files of your WordPress theme. Make sure that the first contains a call to wp_head and the second contains a call to wp_footer.

9.2 How can I use shortcodes in my WordPress theme?

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

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

9.3 How can I use shortcodes in comments?

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

add_filter('comment_text', 'do_shortcode');

9.4 How can I use shortcodes in attributes of shortcodes?

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

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

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

9.5 How can I nest several identical shortcodes?

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

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

Translators