I am calling the typical get_sidebar() method to produce a vertical sidebar on posts/pages. Because of the responsive and multiple format nature of our site, the designer decided to make full-width content posts/pages with no sidebar, but using the same sidebar content below the content, in a horizontal fashion (utilizing bootstrap's grid). Is it possible to use one sidebar instance, and conditionally output multiple formats from the elements of the sidebar?

  • 1
    Could this not be solved using just CSS? – Tom J Nowell Apr 4 '18 at 16:28
  • Short answer: no – cj5 Apr 4 '18 at 16:39
  • 1
    Also note that get_sidebar is just a thin wrapper around get_template_part, look inside the sidebar.php of your theme for the actual code that loads the widgets – Tom J Nowell Apr 4 '18 at 16:56
  • Ok will do. Thanks. If I can set conditions on the page format type, and if get_template_part() is viable that would totally work. – cj5 Apr 4 '18 at 17:02
  • 1
    Specifically look for the calls to dynamic_sidebar. Eitherway I still think the fundamental issue is you're relying on HTML classes to define grids/columns, rather than using CSS to assign them from the stylesheets. SCSS/LESS would make this trivial, all you'd have to do is wrap it in a div with a class you could use to flip between the two formats. Else you're probably going to need to create a whole new sidebar and duplicate all the widgets so that you can change their before and after markup – Tom J Nowell Apr 4 '18 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.