Skip Navigation

[Resolved] Different Layout/Template depends on session/cookie.

This thread is resolved. Here is a description of the problem and solution.

Problem:
Use different templates to different users depending on a cookie.

Solution:
You'll need your own solution for handling the cookies, but you can then switch templates using a little code.

The wpv_filter_force_template filter (https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template) can be used to switch Views Content Template.

If you are using Layouts there is a filter get_layout_id_for_render that you can use, but it's not documented. You would use it something like this:

function tssupp_switch_layout( $layout_id, $slug ){

// test for cookie value and modify current $layout_id as required

    return $layout_id;
}
add_filter( 'get_layout_id_for_render', 'tssupp_switch_layout', 10, 2 );
This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#606984

Hi,
We are trying to build a website for our client.
The clients has 2 different type of customers (builders and home owners)

For new visitors we are going to display a popup with question what kind of visitor they are "builder" or a "home owner" and save the data in cookie or session.
Base on this selection we would like to display different layout/template for some product pages.

Is it possible?

#607103

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Jarrod

Are you using Layouts templates or Views templates?

If you are using Views, the Content Template that will be used is filtered, and so can be modified as you require.

The wpv_filter_force_template filter (https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template) can be used to switch template.

If you are using Layouts there is a filter get_layout_id_for_render that you can use, but it's not documented. You would use it something like this:

[php]
function tssupp_switch_layout( $layout_id, $slug ){

// test for cookie value and modify current $layout_id as required

return $layout_id;
}
add_filter( 'get_layout_id_for_render', 'tssupp_switch_layout', 10, 2 );

I'll assume you can handle retrieving and testing the cookie value, but if you run into problems let me know.