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.

1. Installation

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

Activate the plugin through the Plugins menu in WordPress.

Configure the plugin through the Content Switcher options page in WordPress.

You can also 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.

2. Upgrade

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

Unzip the plugin file.

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 WordPress 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):

7

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

8

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

094

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" />

[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):

There's a land that I heard of, once in a lullaby

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:

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-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]

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]

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]

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]

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:

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

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

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

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

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

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:

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)

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: