I’m building a plugin that requires a full width page for a large table. I want to control the sidebar on that page regardless of the theme being used. How do I either, remove the sidebar programmatically OR change the template for that page programmatically?

  • 2
    There's no guaranteed way to remove a sidebar regardless of theme, but you can control the template with a filter. You may want to create your own template that pulls in the theme header, a content area, and the theme footer, so that you can rely on those elements and not worry about what templates each individual theme may or may not have. wordpress.stackexchange.com/questions/3396/… – WebElaine Sep 6 '19 at 13:12

How do I either, remove the sidebar programmatically OR change the template for that page programmatically?

You can't. Different areas on the frontend and how they're styled are at the discretion of the person who coded the theme. There's no standard WP framework for how to put them together and determine the layout. It could be anything from CSS floats, Bootstrap grids, Flexbox, etc

There may be no sidebars at all, there may be 3, you have no way to know

A naive approach might be to do something like this:

.sidebar, #sidebar { display: none; }

But this has lots of problems:

  • the sidebar might be named .right-sidebar
  • there may be a left and right sidebar
  • it would catch a footer sidebar, or a sidebar inside a block
  • it might eliminate the sidebar but the content area is still the same size
  • it might break the layout of the page

But all of this is moot because even if you could do this, your large data wouldn't work on mobile.

Additionally, if you could do what you're wanting to do, the page content would now be full screen width

How Do Other Plugins Get Around The Need For Theme Templates?

WooCommerce for example provides its own templates, but these have to fit as best they can into the theme, and that doesn't always work. A developer can copy these into the theme and customize them

What You Should Do

Large tables on small screens/areas shouldn't require that your plugin hack the theme. Instead there are other alternatives:

  • Open the data in a new page that doesn't use the theme
  • Use CSS to make it work, e.g. tables that are scrollable, or having it pop out of the content area on hover to fill the entire screen width.

Look up responsive HTML tables, and you'll see lots of ideas. Google Docs spreadsheets are essentially massive tables of data too, yet they can be resized and embedded. Data that's too wide or tall is still shown, you just have to scroll

Using a sledgehammer to force it to work by sawing off parts of a theme won't work, and there's no API for what you're trying to do.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.