Greetings, I recently added the following Javascript to make it so all of the new menu items that appear when a user is logged in (using Ultimate Member plugin), appear on their own row.
// select the x-nav element:
const newNav = document.querySelector(’.x-nav’);
// select first seven children
const nodes1 = […newNav.children].splice(0, 7);
// create wrapper div for first seven children which make up the default menu:
const wrapper1 = document.createElement(‘div’);
wrapper1.classList.add(‘defaultMenu’);
// and append all children:
nodes1.map(node => wrapper1.appendChild(node));
// and add the wrapper to the container:
newNav.appendChild(wrapper1);
// select the children of the node that makes up the logged in (social UM) and shopping cart menu items:
const nodes2 = […newNav.children].splice(0, 6);
// create wrapper div for children which make up the social UM and shopping cart menu items:
const wrapper2 = document.createElement(‘div’);
wrapper2.classList.add(‘socialMenu’);
// and append all children:
nodes2.map(node => wrapper2.appendChild(node));
// and add the wrapper to the container:
newNav.appendChild(wrapper2);
What this essentially did was wrap the first 7 menu items in a new div with the class .defaultMenu and the rest of the menu items in another div with the class .socialMenu. I adjusted the CSS using CSS grid to make everything look fine when a user is logged in, however, when logged out, this Javascript makes it so the div with the .defaultMenu class is located inside the div with the .socialMenu class. This makes the nav look pretty terrible when logged out.
My question is, is there any way to make it where the above Javascript is only used when a user is logged in? Also if you have any other suggestions that would be better for me to accomplish my goal, I am open to them. I am simply trying to make all new menu items that appear when a user is logged in, to be in their own row.
Logged in
https://starscriptlegends.com/wp-content/uploads/2019/09/Logged-in-1.png
https://starscriptlegends.com/wp-content/uploads/2019/09/Logged-in-2.png
Logged out
https://starscriptlegends.com/wp-content/uploads/2019/09/Logged-out.png