Archived topic
Elements - Blocks Priority
21 replies · Started by Fabien on January 15, 2021
Hi,
When using a Block Element, is there a way to add a priority (like you can do with hooks) ?
Thanks
Just to clarify, I am talking about a (Right) Sidebar block type
Hi there,
Priorities will only apply if you use a Hook - you can can use the before_ or after_right_sidebar_content to hook into the same place.
The alternative when replacing the Sidebar, is to create the complete Sidebar for page X and then create a complete alternative for page Y
I guess I've found a "hack", switch to "hook" change priority, go back to "right sidebar" !
Well wouldn't you know :)
I'll let Tom know.
I was looking for the way to change the order of my 4 seperate right sidebar elements.
I could not find anything in the documentation. I saw that other Element Types have the Priority item but Right Sidebar does not.
The "Hack" Fabien suggests works, Thanks for that.
Surely Priority should be an option under the Right Sidebar Elemet Type.
Hmmm... it was never in our consideration that a user may want to add many Right Sidebars to the page, that is where the before and after sidebar hooks should be used.
Ill take a look whether we can adding priority for the sidebar option itself is a possibility.
If I'm not mistaken, every one of those GP Element types gets inserted in the appropriate place via a hook, and all hooks have a priority (with a default of 10 if not specified), so it would seem that exposing that priority would make a lot of sense. Since you can cause multiple GP Elements to fire off for a page, you would expect you would be able to control the order when they all hang off a common hook, like after-main-content. Using a different hook to attach to a different part of the page doesn't make sense; you would expect to be able to write these hooks/blocks independently from each other.
Yeah, its on our list of to dos, hopefully with the next elements update.
For the record, the priority is only missing from the specific block element types that are used to replace a theme template part such as the Right or Left Sidebar. The Priority is available for the Element Type > Hook.
...but not Blocks, which is where it's really needed. Thanks for keeping the issue visible!
FYI - If the Block Element is set to Element Type: Hook then the priority is there:
https://docs.generatepress.com/article/block-element-hook/
Glad to be of help
Hmm, I don't think it works that way anymore... When I create an Element, I choose type Block, because if I choose type Hook the editor I'm given is a code editor, not a Block editor. In that case, I'm not presented with the metabox containing the hook priority as is shown in the article.
That's how I _wish_ it would work, but I do not think the current version does it that way. I'd love to be proven wrong, though!
Nothing has changed in the latest version, as long as the Element Type = Hook you should see this:
https://www.screencast.com/t/dFcILCly
Are you seeing something different ?
When I select Element type Hook, I see what you see, but I don't get the block editor then, I get a code/text editor. When I select type Block, I get the Block editor, but not the hook metabox. So yes, I can make the hook metabox appear, but then I can't edit blocks.
Hi Scott,
May we know what you’re trying to do?
The Hook Element and the Block Element are two different features.
Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
Block Element: https://docs.generatepress.com/article/block-element-overview/
If you’re wanting to use a Block Element - Hook, you’ll need to select Block as the Element type when creating a new element. Then, once in the Block Element edit page, in the Element type in the Element settings, select Hook.
Hope this clarifies!