We just bought the Advances Sidebar Pro. So far all good, but I have two questions:
– How can we add own classes to the <ul> element of a menu? Filter?
– How can we disable the Advances Sidebar Menu Box in pages/posts?
Thanks
Custom UL classes and disable menu box in pages/posts
Resolved
You may accomplish this with a template override.
Create a folder in your active theme called ‘advanced-sidebar-menu’
Copy the page_list.php or category_list.php from the plugins ‘views’ folder into the folder you just created.
Edit the ul elements in these new files.
Thanks for your feedback.
And what about that?
How can we disable the Advances Sidebar Menu Box in pages/posts?
If you add the following code to your active theme’s functions.php file it will remove the box.
remove_action( 'do_meta_boxes', array( Advanced_Sidebar_Menu_Pro__Meta__Title::instance(), 'createMetaBox' ) );
Unfortunately this does not help.
The box is still there
Thanks
Thanks, I’m talking exactly about this.
I placed the code in a plugin we load for modifications:
remove_action(‘do_meta_boxes’, array(
Advanced_Sidebar_Menu_Pro__Meta__Title::instance(), ‘createMetaBox’
));
But the metabox is still there.
I have another question regarding Menus for categories.
I want to show the categories in the blog archive and single pages, but for some reason they do not appear.
If you place the code inside a plugin it must be wrapped in an action otherwise it will run too soon and be unable to de-register the action which is not previously registered. It will work like so.
add_action( 'do_meta_boxes', function() {
remove_action( 'do_meta_boxes', array(
Advanced_Sidebar_Menu_Pro__Meta__Title::instance(),
'createMetaBox'
) );
}, 0 );
The plugin requires a category or post to know which categories to display. If you want it to display elsewhere this may be accomplished via a couple of filters.
add_filter( 'advanced-sidebar-menu/menus/category/is-displayed', '__return_true' );
add_filter( 'advanced_sidebar_menu_category_ids', 'include_all_parent_terms', 1, 4 );
function include_all_parent_terms( $term_ids, $args, $instance, $object ) {
if ( 'category' !== $object->get_taxonomy() ) {
return $term_ids;
}
return get_terms( array(
'parent' => 0,
'fields' => 'ids',
'taxonomy' => 'category',
'hide_empty' => true,
) );
}
Thanks a lot for your quick feedback!
Got rid of the metabox 🙂
Unfortunately, the filter you provided do not help.
The sidebar menu containing the categories is still not visible.
Any idea?
Are other widget displaying in this sidebar? Like if you add a “Text” widget does it display?
Another thing worth mentioning, is the categories must have posts assigned to them to show up.
Yes, other widgets appear fine.
And the taxonomy categories has some categories with associated posts defined.
Turns out because your categories are all on the same level you must have the following options checked in the widget to show up:
Display parent category
Display menu when there is only the parent category
Thanks a lot.
Is there a way to define additionally where to show the menu.
Let’s say on blog and specific archive pages only?
There are a number of plugins which allow you to show widgets on particular sections. Here are a couple examples (I am in no way affiliated with these other plugins and can not guarantee their functionality):
https://wordpress.org/plugins/restrict-widgets/
https://wordpress.org/plugins/widget-options/
Otherwise if you would like to do this programmatically, you may update the previously sent filters to:
add_filter( 'advanced-sidebar-menu/menus/category/is-displayed', '__return_true' );
add_filter( 'advanced_sidebar_menu_category_ids', 'include_all_parent_terms', 1, 4 );
function include_all_parent_terms( $term_ids, $args, $instance, $object ) {
if ( 'category' !== $object->get_taxonomy() ) {
return $term_ids;
}
//ADD CATEGORIES YOU WANT TO DISPLAY TO THIS ARRAY
$categories = array( 'news' );
if( is_page( 29 ) || is_category( $categories ) ) {
return get_terms( array(
'parent' => 0,
'fields' => 'ids',
'taxonomy' => 'category',
'hide_empty' => true,
) );
}
return array();
}
This will display the widget on your blog page and whatever categories you add to the $categories array, marked with.
//ADD CATEGORIES YOU WANT TO DISPLAY TO THIS ARRAY
I have another question.
When I open a single post page from a CPT, then the menu disappears.
I checked the template and the sidebar is included.
Any idea?
It appears you are using an “Advanced Menu” widget on the page. I am unfamiliar with that widget but I took a quick look anyway. I have confirmed that it is added to that sidebar and the options appear to be correct.
Due to my lack of knowledge of this widget, I am unable to provide a solution. I recommend reaching out to the developer of the widget to see if they have a solution.
Sorry!
I confused the widgets!
But thanks for looking into it!