on my website I have a problem. In my menù I have a voice called "area riservata".

What I want to do is: insert a condition on this specific voice, so when a user click on this voice a not logged-in user will go to a page ( called "diventa Yallers" where they can register on my site ) and a logged-in user will go to another page ( called "profilo", where users can see their profile settings etc ).

  • Share some code so we can see what the menu structure is like. It should be reasonably straightforward using the is_current_user() function to output conditional jQuery that re-routes the user. Jan 26, 2020 at 16:43
  • This is the header's code: pastebin.com/3U10tiT7
    – paolucci
    Jan 26, 2020 at 16:55
  • That doesn't show any indication as to what the menu structure is like. Jan 26, 2020 at 20:39

1 Answer 1


I went to the GeneratePress site and looked at one of their demos:

<nav id="site-navigation" class="main-navigation sub-menu-left" itemtype="https://schema.org/SiteNavigationElement" itemscope>
    <div class="inside-navigation">
        <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
            <span class="mobile-menu">Menu</span>
        <div id="primary-menu" class="main-nav">
            <ul id="menu-menu-1" class=" menu sf-menu">

                <li id="menu-item-594520" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-594520"><a href="https://generatepress.com/">area riservata</a></li>

                <li id="menu-item-594521" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-594521"><a href="https://generatepress.com/premium/">Premium</a></li>

    </div><!-- .inside-navigation -->
</nav><!-- #site-navigation -->

So in your function's PHP you can try dropping this:

function change_area_riservata_url() { ?>
    <script type="text/javascript">
        jQuery( document ).ready( function($) {
            <?php if( is_user_logged_in() ) : ?>
                var hrefAtt = 'https://google.com'; //the URL if user is logged in
            <?php else : ?>
                var hrefAtt = 'https://bing.com'; //the URL if NOT logged in
            <?php endif; ?>
            //Make sure the correct ID is in place
            $( '#menu-item-594520 a' ).attr( 'href', hrefAtt );
        } );
} ?>
add_action( 'generate_after_header', 'change_area_riservata_url', 20 );

Obviously you'll want to edit the URLs and the ID of the menu item so that it matches your site.

  • 1
    Just tried it, it works!
    – paolucci
    Jan 27, 2020 at 11:46
  • Fantastic. Glad it's all sorted. :-) Jan 27, 2020 at 15:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.