Filter: Sidebars Manager filter

Marketers Delight 4.6.2 added the new Simple Sidebars feature that allows you to set custom sidebars across your site in various ways.

By default, you can assign custom sidebars to WordPress Posts and Pages. If you use a plugin that adds custom post types and would like to extend the Sidebar Manager to account for them, follow the instructions below.

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.

Easy Digital Downloads

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:

/**
 * Filter into MD's sidebar data and add custom post
 * types to Sidebars Widgets Manager.
 *
 * @since 1.0
 */

function md_child_theme_sidebars_post_types( $sidebars ) {
	$sidebars['download'] = array(
		'archive' => true,
		'single'  => true
	);

	return $sidebars;
}

add_filter( 'md_filter_sidebars_post_types', 'md_child_theme_sidebars_post_types' );

Tip: for quicker reference in the future, you can grab this snippet from the Snippets library.

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:

Filter custom post type sidebars

As you can see, you can now control the sidebar on your custom post types right from the slick new MD Sidebars Manager.

Leave a Comment