Archived topic
reposition generate_insert_into_navigation
5 replies · Started by Michael on December 15, 2020
Hello,
I'm using the following code to insert a "login" link with redirect js to the menu
add_action( 'generate_inside_navigation','generate_insert_into_navigation' );
function generate_insert_into_navigation(){
if (! is_user_logged_in())
{ ?>
<a href="/login/" onclick="window.location = '/login/?redirect_to='+window.location.href; return false;">Login</a>
<?php }
}
This works fine, but I would like to know if there's an easy way to
1. move its position to the end of the menu?
2. add it to the off-canvas menu?
Thanks in advance!
Hi there,
can you share a link to your site so i can see the layout for positioning it at the end.
The Off Canvas Panel has two hooks inside it:
before menu: generate_inside_slideout_navigation
after menu: generate_after_slideout_navigation
So you can simply hook your function in there as well.
Thanks, David.
Here's the link https://app-5fd0af24c1ac1a221c18b62f.closte.com/
The first login menu item is added via the hook and I would like to position it after 'browse'
But I'm rethinking my approach. Aside from repositioning, I also need it to use the same css for my nav. I'm using the hook only because I need the onclick function to add a redirect to the login URL. Do you recommend a different approach?
Regards,
Mike
Hi there,
Have you considered adding it as a regular menu item? Then you could just give it a class and target the class with some JS instead of writing it inline.
cool. thanks, tom. I got it working now!
You're welcome :)