Create and manage thousands of dynamic content versions directly from a CSV file.
Why should I use Dynamic Content from CSV?
Creating dynamic content using an If-So trigger is super easy and useful. But if you’re applying thousands or even only dozens of dynamic versions, it can become time-consuming, and the page-load delay becomes noticeable.
The If-So Dynamic Content From CSV extension is a new way to easily create and manage your dynamic content. It allows you to create and manage thousands of dynamic content versions directly from…well…a CSV file.
If-So Dynamic Content From CSV is flexible enough to suit any need and syncs with If-So. Its functionality includes:
- Compatibility with HTML as the CSV content
- Can be used with page caching
- Displays content that can be used anywhere on your site or on your page templates
Which Conditions Can You Set with If-So CSV?
- Query-String (URL Parameter): Show content based on the value of a parameter
- Geolocation: Show dynamic content based on the country, state, or city name
- User Time zone
- Date/time
- Page URL
- Post ID
- User IP
- User Details (email / user name)
- Referral Source
- Custom User Profile Field (requires the extension)
If you want to show dynamic content based on other If-So conditions, feel free to check out our dynamic triggers.
How to set up Dynamic Content from CSV?
A single CSV table of dynamic content is called a “Bulk”. The example below explains how to set a bulk with a query-string condition. The same principle applies to the rest of the conditions.
Step1: Create a CSV file with the following structure:
- Column A – the values of the condition. One value per row. The table below shows the required values for each condition.
To make things easier, feel free to download the template file from this link
Condition | Values in column A | Example |
---|---|---|
Query String | The value of the query parameter – value only, without apostrophes. | If the name of the parameter you had set when you created the trigger was “example”, and you’d like to display content when the page URL contains the query ?example=”value1″, then the value in column A should be value1 |
Geolocation | The value changes depending on the level (country, state, city, continent). Learn more. | |
Page URL | The Page URL, including the protocol (http:// or https:/), including www, and including / (slash) at the end of the URL. | To display dynamic content on the current page, the value should be: https://www.if-so.com/dynamic-content-from-csv/ |
Post ID | The post ID (how to get the post ID) | |
User IP | The user IP | |
Date/ time | The date and time according to the format selected when you create the bulk. | |
Cookie / Session Variable Value | Cookie – the cookie value Session – the session variable value. | |
User Data | Username – The username as it appears in the user profile. Email – The user email as it appears in the user profile. | |
Referral Source | The referral page URL, without http:// or https://, without www, and without a / (slash) at the end of the URL. | |
Custom User Profile Field | The Meta Field key (name) |
Default content – Default content is the content that will be displayed if the condition is not met. To set up a row of default content, select one of the rows and set column A with the value “default-content” (note the hyphen between the words!)
- Columns B: the dynamic content that will be displayed if the URL contains the parameter value (can be HTML if you want).
- Column C-F (optional): columns C-F are additional columns you can use to display dynamic versions in other places on your page.
After uploading the CSV to your site, you will receive unique shortcodes which correspond to the content of each column.
Step 2: Upload your CSV
- On your WP dashboard, go to If-So > Bulks
- Click “Add a new bulk”
- Name your Bulk (the name is for your reference only)
- Under “Condition Type”, select “Query String”
- Set your parameter (the parameter is the bolded part in the following example: www.example.com?color=red). The parameter can be whatever you want, except for several WordPress reserved terms.
- Select your CSV separator – by default, the separator should be “Comma”. If your content contains commas you might want to set a different separator when you save your file.
- Upload your file.
- Click “Create Bulk”.
Displaying your dynamic content
- The bulk you created in the previous step should now be shown on the If-So > Bulks page. Find it and click “View”.
- Copy the shortcode of the content (column) you want to display.
- Paste the shortcode anywhere on your website.
Loading the dynamic content from CSV using Ajax
If you are using cache on your site (particularly page cache), you can load the dynamic content using a separate Ajax request that will take place after the static content loads from the cache. This way, you can use dynamic content while continuing to enjoy the advantages of caching.
The If-So Dynamic Content From CSV extension relies on the default Ajax Loading settings of the core If-So plugin. However, if you want to override those settings, you can simply add the parameter ajax=”yes” or ajax=”no” to the CSV shortcode. For example:
[ifso_bulks id='1' column='B' ajax='yes']
Learn more about the Ajax Loading (Page Caching Compatibility) option
Embedding the Shortcode in a Page Template
If necessary, you can embed the CSV shortcode directly in your theme files. Just apply the shortcode using the ‘do_shortcode’ function. Here’s an example:
<?php echo do_shortcode('[ifso id="XXX" ajax="yes"]');?>
Configuring “Recurrence” for a consistent content experience
The recurrence option enables you to ensure the consistency of a user’s experience. Once a user has visited the website and seen a certain dynamic version, the same version will be displayed every time they encounter the dynamic trigger.
Recurrence settings are managed at the “bulk” level, either during the creation of the bulk or through the bulk settings after its creation.
Troubleshooting
- Content in columns A is broken after uploading a CSV file or saving a bulk
By default, the number of allowed characters in a single cell in column A is 55. This limitation is intentional to optimize the loading speed of the dynamic content for users who don’t need a higher number of characters.
To change the max allowed number of characters in column A:
- Add the code below to your functions.php file.
- Visit one of your website pages (it will run the code).
- Remove the code from your functions.php file.
function modify_content_column(){ global $wpdb; $wpdb->query("ALTER TABLE {$wpdb->prefix}ifso_bulks_content MODIFY COLUMN version VARCHAR(100);"); } add_action('init','modify_content_column');
The code above will change the number of allowed characters to 100. You can replace the number in the code with any other number. Bear in mind that if your file consists of many dynamic versions (thousands), there might be some loading speed implications (they will probably be insignificant, but it is worth checking).
Please note that if you reduce the number of allowed characters, the new number you set will affect content created in the past.
- Content is broken after uploading a CSV file or saving a bulk (in any column except column A)
By default, the number of allowed characters in a single cell (except column A) is 1024. This limitation is intentional to optimize the loading speed of the dynamic content for users who don’t need a higher number of characters.
To change the max allowed number of characters in the relevant column:
- Add the code below to your functions.php file.
- Visit one of your website pages (it will run the code).
- Remove the code from your functions.php file.
function modify_content_column(){ global $wpdb; $wpdb->query("ALTER TABLE {$wpdb->prefix}ifso_bulks_content MODIFY COLUMN content VARCHAR(2048);"); } add_action('init','modify_content_column');
The code above will change the number of allowed characters to 2,048. You can replace the number in the code with any other number. Bear in mind that if your file consists of many dynamic versions (thousands), there might be some loading speed implications (they will probably be insignificant, but it is worth checking).
Please note that if you reduce the number of allowed characters, the new number you set will affect content created in the past.