change a menu completely using a javascript library
-
I have been playing around with a menu made with lettering.js and have created the effect as I wish. My final goal is to use it in WordPress (only I must have the tabs horizontally) on a newly installed theme. I hope it can be achieved even if I’m not a developer. What’s the path to follow?
-
This topic was modified 6 years, 1 month ago by
Jan Dembowski.
-
This topic was modified 6 years, 1 month ago by
-
You’ll become a “developer” in a small sort of way because you’ll need to learn something about it along the way. First create a child theme to contain your work so updates don’t overwrite it.
Your theme will have already styled the menu. You can completely change this by adding the CSS you want to your child’s style.css file.
You’ll need to get jQuery and lettering.js loaded onto your pages. This is done with wp_enqueue_script(). Be sure to specify
['jquery']as a dependency when enqueuing lettering.js. Be sure to read the notes about action hooks and the user notes about noConflict mode on the linked docs page.When you call the .lettering() function, the selectors you use will be different than the examples because a WP menu uses a different HTML structure. This is not a problem, any structure can be handled as long as you specify the right selectors.
Use your browser’s element inspector developer tool to help you determine the right CSS for the menu. This all will be a frustrating process when you start out. Stick with it and you will be rewarded with new found powers over your site. Test your work frequently and celebrate every small achievement, you deserve it. If you get a little rush when something goes right, no matter how trivial, you will find this sort of work rewarding and will do well. Good luck and happy coding!
I had to change my theme because the functionalities were not as I want them to. However I want to retain the design. I believe it’s not that easy because it’s not only a matter of CSSing elements. For instance, I need to swap searchbar/menu and themes apparently seem to “lock” such elements (that’s why I was preferring a “theme from scratch” approach, but it’s beyond my skills). But WordPress makes it possible, then I guess it will be.
Now, I’m thinking that maybe it’s “easier” to avoid handle the menu on the page but on a full screen overlay. Do you think it’s a better approach in terms of tweaking the childtheme?Hi arsenalemusica,
I didn’t notice it was you when I last replied. I might have phrased things differently, though the facts of implementing lettering.js wouldn’t change.
I wouldn’t say an overlay would be easier. Swapping menu/search elements doesn’t sound all that serious to me, even considering your skill level. The reality depends on the theme specifics. You ought to have a child theme regardless. Usually elements like that occur in header.php. Copy it or whichever template needed to the child. Identify the blocks of code dedicated to each feature and reverse the order in which they occur. In some cases that’s all there is to it. In other cases the related CSS might need adjustment as well.
I imagine you might find “Identify the blocks of code” intimidating. Fair enough. You have a backup file, so there’s little to lose in trying other than time spent. The blocks would generally be surrounded by HTML. Use your browser’s element inspector developer tool to help you identify the HTML that goes with each element. If you can identify the same HTML in template code, you’ve identified the blocks of code. You don’t need to understand the PHP code within, only know what makes up the HTML for each element and move it all so the positions are swapped.
Even if you really preferred an overlay, you’d still want to identify the current elements in order to move them to an overlay. While there is something to be said in separating custom work from the theme, minimizing how much is changed to get what you want is important if one’s skills are limited.
it’s me π thank you for your patience in throwing some lights on me.
I’m all sorted with a childtheme and I also thought that maybe it’s just a matter of finding the code in the templates and move them accordingly. That’s what I’ve done normally, but in this case the theme is packed with the hateful VisualComposer that’s why it feels that the theme elements are stuck (I hate blocks, it’s easier to me to scan a php code than tweaking standard blocks).
Can I give you just an example? On my old site I had a beautuful searchbar on top, but on this theme is stuck below the map.But even if I find the html driving the block, we are talking about functionalities not just design so I fear that things will stop working. I shall start lookign at the code of this new theme, though.
PS. I also want to recycle the old blog style, and that’s a more difficult task. Why I changed theme then, if I didn’t like the design? Again, I needed the backend/frontend functionalities. :S
Ugh, I hear you about page builders like VC. I’m not keen on the WP block editor either, though I’m learning to live with it. Supposedly moving components in VC should be even easier than editing HTML but I’ve zero experience with VC.
It seems odd to me that header items like search and menus would be part of VC. I’d expect it to be template code and VC only used for regular content. But it’s not hard to imagine a theme doing it differently.
In general, it ought to be easier to alter appearance and style than to gain certain functionality, so choosing a theme by functionality over style was the right choice. Doesn’t make changing the style any easier. If it were left only to CSS it wouldn’t be so bad, but often HTML needs to be a certain way to get a certain layout. As it is for the menu/search order.
You’d be better off altering the current style to address what you most dislike instead of trying to make it match something you had previously. When it comes to swapping element order, if the element’s container can be styled using the flex-box CSS scheme, the ordering of elements within can be defined with CSS alone. Flex-box is a more advanced CSS scheme that I have little experience with, but it has intriguing possibilities if it can be made to work. It could be difficult to attain if the HTML isn’t set up to take advantage of it.
I know you’re not a developer so such a thing might be out of reach, but it’s good to know what options are available. Non-developers can sometimes still achieve certain customization by learning just enough to accomplish the immediate task. If you do that enough, you eventually pick up enough knowledge to be considered at least a novice coder. Lots of developers started out that way.
Coders everywhere cried out to stay away from block builders… and now WP has turned into one π I have experience with VC and it’s fine for standard layouts, but it doesn’t help if you want to be creative, and it really doesn’t help for tweaking templates (it would be great if someone invented modular code to be handled as blocks… but that’s utopia).
However, on this theme they have been able to let VC create things, like the search-bar itself, but it can only be inserted in the container, not on header/footer (which is what I want to achieve). It must be the reason why, by looking at the templates, I don’t find sections that I could move around but functions and “if” conditions. Very difficult to spot a hole where to drop a custom code.
By the way, from the information I gather, Flexbox cannot be used together with VC.All this sounds like I need some help from the outside….
However, I think I’m gonna go for an overlay menu. It would help me also to place the search-bar in the header (since the menu will not be there)…
The topic ‘change a menu completely using a javascript library’ is closed to new replies.