Add Custom Sidebars to Post Types
Step 1: Get the Post Type ID
In this example, I’m using my favorite eCommerce plugin Easy Digital Downloads. From my admin panel, I go to the “Downloads” tab the plugin adds and once there, I look at the URL to find the ID.
In this case my custom post type ID is download.
Step 2: Add Filter to child theme functions.php
file
Now that I have my post type ID, I can simply plug it into the md_filter_sidebars_post_types
filter in my child theme’s functions.php
file like so:
You’ll notice the post type ID is set as an array and inside are 2 keys: archive and single. Based on whether your custom post type has an archive page (think of your blog posts homepage vs. Pages) you can choose whether or not you’ll need both select fields in the Sidebars manager.
In the case of EDD, the plugin creates a listing to show all of my downloads and creates single post entries, so I activated the filter to target both scenarios.
Step 3: Save Filter, Upload Child Theme, and Set Your Custom Sidebars
Once you add the filter to your child theme, save and upload it, you can begin adding sidebars to custom post types!
What did this filter accomplish? Go check out the Sidebars Manager:
As you can see, you can now control the sidebar on your custom post types right from the slick new MD Sidebars Manager.