Skip Navigation

[Resolved] Adding WP conditional script to Views

This support ticket is created 6 years, 6 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#837789
Screen Shot 2018-05-07 at 10.38.01 AM.png
Screen Shot 2018-05-07 at 10.31.50 AM.png

Dear Sir/Madam,

As I don't know how I can add the WP sidebar to a Layout, so I build a content template "sidebar" and insert into the Layout.

In general, I can use the widget_logic to standard WP sidebar to control the show/hide of widget like is_home(), is_page(99), how can I apply such script to a content template?

Best regards,

Kelvin.

#838587

Dear Kelvin,

I suggest you try with Layouts filter hook "get_layout_id_for_render" to specific the layout you want to render, for example:

1) Create two different layouts

a) default layout A( ID 123), with content template cell in sidebar
b) layout B(ID 456), without sidebar.

2) Assign posts/pages to the default layout A

3) Add some codes in your theme/functions.php, for example:

function assign_layout_by_id_func( $id, $layout ){
  
        if( (is_home() ||   is_page(99)) && $id == 123){
            $id = 456;
        }
        return $id;
    }
add_filter('get_layout_id_for_render', 'assign_layout_by_id_func', 10, 2);