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

Example (random number between 0 and 5):

Result (with a little formatting):

0

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

Example (random number between -3 and 8):

Result (with a little formatting):

3

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:

Example (random number belonging to { 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:

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

Result (with a little formatting):

023

Other example (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:

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:

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:

Example:

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:

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:

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:

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

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:

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:

Résultat:

Your IP address is 54.204.163.26.

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

Example:

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:

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:

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

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

Example:

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:

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:

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:

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:

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:

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:

Result:

JavaScript enabled: yes

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

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:

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:

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:

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:

Translators