I've created the plugin that adds custom post type and custom taxonomis for this post type. Templates for the post type and the taxonomies are located in plugin folder. Now I need to add sidebar for the post type and taxonomies pages. I have the following code to add template for archives page:
// Filter the archives
add_filter('archive_template', 'mytype_archive_template');
function mytype_archive_template($archive) {
global $wp_query, $post;
// Checks for single template by post type
if (is_post_type_archive('type')) {
if (file_exists(plugin_dir_path(__FILE__) . '/archive-mytype.php'))
return plugin_dir_path(__FILE__) . '/archive-mytype.php';
}
return $archive;
}
That's working good, so I've tried to use the same code for sidebar:
function mytype_get_sidebar($mytype_sidebar) {
// load sidebar template
if (file_exists(plugin_dir_path(__FILE__) . '/sidebar-mytype.php'))
return plugin_dir_path(__FILE__) . '/sidebar-mytype.php';
// Default return
return $mytype_sidebar;
}
add_filter('get_sidebar', 'mytype_get_sidebar');
And then on the page where the sidebar should be:
get_sidebar ( apply_filters( 'mytype_get_sidebar', '' ) );
But it doesn't work. var_dump returns NULL:
$my = get_sidebar ( apply_filters( 'mytype_get_sidebar', '' ) );
var_dump($my);
Is there any way how to do that?
Thanks in advance.