1

With classic templates it was easy to understand how to overwrite how Wordpress navigation menu was rendered, but I'm struggling with the new Theme blocks approach. I know it uses the navigation block and through the Page Editor I'm able to configure several properties, but I actually need to change the generated navigation menu html.

The template I'm using is including the block through:

<!-- wp:navigation {"layout":{"type":"flex","setCascadingProperties":true,"justifyContent":"right"}} -->
<!-- wp:page-list {"isNavigationChild":true,"showSubmenuIcon":true,"openSubmenusOnClick":false} /-->
<!-- /wp:navigation --></div>

And I would like to change the html rendered by WordPress navigation. I think I could use apply_filters('render_block') and then depending on the block return a different html, but is that the best approach?

The reason why I'd like to change how the navigation menu is rendered is because I'm migrating an existing website into Wordpress system and the menu render (html structure) is already implemented so I'd like to apply the same but in wordpress.

2
  • you're right that these blocks use PHP to render themselves, hence the lack of HTML in the content/html file, I forget the name of the filters but 5.8 and 5.9 introduced filters for rendering and intercepting the PHP rendered content before display. I notice though that you did not mention why you needed to change or it what you needed to do, so there may be better/superior/easier ways to achieve your goal. If you can edit your question to provide some context then it will lead to better more informed answers that are more helpful
    – Tom J Nowell
    Commented Feb 7, 2022 at 17:47
  • @TomJNowell added more info the question
    – out_sid3r
    Commented Feb 7, 2022 at 18:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.