Wordpress - Gutenberg: Sidebar for specific post type
I know this question is a few months old by now, but I got around this issue using the following code and thought it might be helpful for others. There might be a better way, but this works:
import ColorSchemeSelect from "./components/color-scheme-select";
import includes from "lodash/includes";
const { select } = wp.data;
const { registerPlugin } = wp.plugins;
const { PluginSidebar } = wp.editPost;
registerPlugin('ahr-sidebar-post-options', {
render() {
const postType = select("core/editor").getCurrentPostType();
if ( !includes(["post", "page"], postType) ) {
return null;
}
return (
<PluginSidebar name="ahr-sidebar-post-options" icon="admin-customizer" title="Color settings">
<div style={{ padding: 16 }}>
<ColorSchemeSelect />
</div>
</PluginSidebar>
);
},
});
In my example I only wanted to show a certain sidebar for posts and pages, so I'm using !includes(["post", "page"], postType)
to test wheter or not the sidebar should be shown. If you only want it for one specific post type you'd just go postType === "my-post-type"
instead.