Sidebar, Custom post types and plugins


I’m sticking to best practice and keeping custom post types out of my theme and instead I’m developing a plugin to create them. I’m going to include templates with the plugin that can be copied into a theme or child theme, however I want to make sure that the sidebar is hidden on these.

I’d like my theme to hide the sidebar for ANY custom post type by default, regardless if its from my plugin or another plugin. Can anyone suggest a way to make this so?

What have you tried? Assuming you’re using 8.5.0,

If I understood correctly your question, here is what I’ve done for that…

In lib/setup.php add is_page() to the bottom of the array where function display_sidebar() is.

It should look like this:

 * Determine which pages should NOT display the sidebar
function display_sidebar() {
  static $display;

  isset($display) || $display = !in_array(true, [
    // The sidebar will NOT be displayed if ANY of the following return true.
    // @link

  return apply_filters('sage/display_sidebar', $display);

Humm, yeah but then I have to specify this if a new plugin is added with theme files/front-end templates of its own. I am looking for a way to say “do not display sidebar for any custom post type that could possibly be added by a plugin”.

You could do this by testing the post type with get_post_type(). If it’s not page or post then it’s safe to assume it’s added by a plugin, so don’t show the sidebar.

1 Like

Yeah that is what I was looking for! Thanks! I feel rather silly now…