- This topic has 10 replies, 2 voices, and was last updated 4 months, 3 weeks ago by
David.
-
AuthorPosts
-
November 1, 2022 at 2:26 am #2396406
Michel
Hi,
I have created a custom widget area to display different custom navigation menus in various sections of my site.
I used a plugin (“Conditional Widgets”) to display them conditionaly (only when in specific “sections” of the site).
Following the block-based widget management update, this plugin no longer works.I am trying to manually recreate the same kind logic with Elements (using a Block element for instance), which allows me to fine tune display conditions, but I fail to find a way to output the block in the correct widget area. Is there a way to achieve that?
November 1, 2022 at 3:46 am #2396520David
StaffCustomer SupportHi there,
Elements only work with Hooks.
Before we look at alternative options – you can disable block widgets, so that plugin will work:
https://docs.generatepress.com/article/disable-the-block-editor-in-widgets/
is that an option. Let me know.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 4:11 am #2396559Michel
Hi David,
Thank you for your quick reply and insightful tip.
Moving back to old widgets might be a temprary solution (although I would have to check that going backwards won’t create other side effects), but I don’t think it is a good idea to use that in the long term, either because wordpress (or plugins / themes) will stop supporting “old widgets” altogeher, or because this specific plugin is no longer maintained, and will become incompatible with newer wwordpress versions (or newer php versions, etc.). So I would rather find a more solid GeneratePress “native” solution, even if that involves some manual coding.
I understand that Elements are triggered by hooks, and I managed to conditionaly output a block above the main content for instance. But I cannot seem to find a hook that triggers when a custom widget area (or custom sidebar) is being generated / showed on the page.November 1, 2022 at 4:39 am #2396594David
StaffCustomer SupportWhat are the Custom Widgets areas ? And how are they being added ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 5:33 am #2396659Michel
I created one custom widget area (that I called content_top) using register_sidebar() in the functions.php of my child theme.
I also created a hook Element that just calls dynamic_sidebar for that custom area on specific pages.The widgets (various menus) were all added to that custom area throught the old widget interface, and displayed conditionaly using this Conditional Widgets plugin, which allows to specify display conditions at the individual widget level.
November 1, 2022 at 5:52 am #2396681David
StaffCustomer SupportAre there other widgets in those areas? Or are they just there for the navigaiton menus?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 5:57 am #2396686Michel
Only for navigation menus
November 1, 2022 at 6:32 am #2396720David
StaffCustomer SupportOk. If i understand correctly, and forgive me i am having a day of brain fogginess lol
1. when you registered your custom widget areas you would have hooked them in ( add_action ) to some hook.
2. you can create a block element and set the Hook to the above hook.
3. Add a nav block to the element
4. Set the Display Rules to places you need it displayed
Let me know
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 1, 2022 at 8:25 am #2396937Michel
Thanks David.
Not sure I fully understand your suggestion though.
Whatever I do to conditionnaly display a block Element, I have no way to make it appear inside that custom widget area (cwa).Sure I can use the same hook I used to display the cwa (
generate_before_main_content
in my case). But it will show either above or below the custom widgets area, not within.If you were suggesting that actually use the same hook I used to register in my functions.php (
widgets_init
), I doubt it would work at all, and there is still the same fundamental issue that I cannot execute code (or trigger an Element) inside the cwa.Or am I missing something here?
November 1, 2022 at 9:19 am #2397002Michel
… or maybe you are suggesting that I get rid of the cwa altogeter, and just directly output the menu block at the same place where the cwa was displayed?
That would be a possibility, since that cwa is used only for these specific menus. All I will need is to refactor my CSS.Thank you for your help.
MichelNovember 1, 2022 at 9:41 am #2397036David
StaffCustomer Support… or maybe you are suggesting that I get rid of the cwa altogeter, and just directly output the menu block at the same place where the cwa was displayed?
Thats correct.
Let us know if you need any help with styling.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.