roryashfordbentley / wordpress-bem-menu Goto Github PK
View Code? Open in Web Editor NEWBetter menu implementation for Wordpress using BEM syntax
Better menu implementation for Wordpress using BEM syntax
Would you be interested in a pull request implementing WordPress PHP Coding Standards in the plugin?
I'd prepare one, if so…
I wanted to bring up an issue more for the sake of discussing the best practice, and getting opinions.
The default for sub-menus, Wordpress-Bem-Menu nests elements, which I think is frowned upon. So we have classes like:
.menu (block)
-- .menu__item (block__element)
-- -- .menu__sub-menu (block__element)
-- -- -- .menu__sub-menu__item (block__element__element)
IMO, I think it would be more inline with BEM methodology to either split sub-menu
into its own block, with its own elements (i.e. .sub-menu__item
), or make being a sub-menu a modifier, and leave the elements in it the same as for the parents:
.menu (block)
-- .menu__item (block__element)
-- -- .menu--sub-menu (block--modifier)
-- -- -- .menu--sub-menu .menu__item (block--modifier block__element)
I think the latter is the more sensible solution, as a "sub menu" isn't really a block-level item, as it cannot exist outside of the menu. The fact that it is "sub" is just a modification of the menu, the element structure is the same.
Other than some minor tweaking of the item_css_class_suffixes
array (with no good affect), I haven't looked closely at how the code would need to be modified to accommodate something like this -- or even if it is possible. I thought I'd mention it all the same though, as I really like this project.
Hi, new to WP so struggling a little with getting this working - would it be possible to give some more detailed installation/implementation instructions? Currently getting 'You need to first define a menu in WP-admin' and unsure how to resolve.
Thanks!
All of the above referred by dummy-uploader.php line 127, 128
First of all, thank you for your effort in this piece of code! :)
Problem: when you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active.
Thanks in advance for resolving this!
Custom CSS classes in menus are not in plugin's output. That seems like a useful missing addition.
This is, no doubt, an issue with my misunderstanding but...
I've pasted the relevant php into my functions.php and that seems to run smoothly.
I've set menu location in wp-admin > 'primary'.
I've added <?php bem_menu('primary', 'nav'); ?>
into my header.php.
But I get - "You need to first define a menu in WP-admin" when I load up a page to see what happens.
Any ideas as to what I'm doing stupidly wrong?
I recently encountered a situation where I needed to add a modifier to the BEM menu <ul>
but the modifier did not need to be added to children.
an example:
<ul class="main-menu main-menu--secondary">
<li class="main-menu__item"><a href="#">Page 1</a></li>
<li class="main-menu__item"><a href="#">Page 2</a></li>
<li class="main-menu__item"><a href="#">Page 3</a></li>
</ul>
I propose adding an implementation along these lines:
<?php bem_menu( 'my_menu', 'main-menu', array('main-men--secondary','main-menu--something-else') ) ?>
I think that having the last argument accept an array allows for a lot more flexibility but it keeps the code really lean.
I'm using Composer a lot these days to bring vendor code such as this into my WordPress theme. I was wondering if it'd be possible to add a composer.json file to allow this to occur?
How can I add two or more menu if each of them should be an another block with a few changes in html structure?
For example top-nav
, top-nav__item
... and footer-nav
, footer-nav__item
The post ids in the class syntax are wrong and are actually the menu ids.
This behaviour is the same in WP core I believe.
If you have a CPT with categories taxonomy. If you are on the archive page the active category is marked as --parent
but if you visit the 'single.php' template it is not.
First -- this is excellent, thanks for this! I'm looking to BEM-ify my themes, and this was a huge help.
Just wondering if you've any plans for adding BEM classes to the menu links. I realize .menu__item a
works just fine, but had thought using classes over elements was a better practice, and so something like .menu__link
would be more appropriate.
Either way, thanks again. Super helpful.
Hi!
How can I add serial numbers to first level menu items as modifiers:
.main-nav__item_order_1
, .main-nav__item_order_2
, and so on..?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.