admin管理员组

文章数量:1410688

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 ).

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 Improve this question asked Jan 26, 2020 at 16:31 paoluccipaolucci 33 bronze badges 3
  • 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. – Tony Djukic Commented Jan 26, 2020 at 16:43
  • This is the header's code: pastebin/3U10tiT7 – paolucci Commented Jan 26, 2020 at 16:55
  • That doesn't show any indication as to what the menu structure is like. – Tony Djukic Commented Jan 26, 2020 at 20:39
Add a comment  | 

1 Answer 1

Reset to default 0

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/SiteNavigationElement" itemscope>
    <div class="inside-navigation">
        <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
            <span class="mobile-menu">Menu</span>
        </button>
        <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/">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/premium/">Premium</a></li>

            </ul>
        </div>
    </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'; //the URL if user is logged in
            <?php else : ?>
                var hrefAtt = 'https://bing'; //the URL if NOT logged in
            <?php endif; ?>
            //Make sure the correct ID is in place
            $( '#menu-item-594520 a' ).attr( 'href', hrefAtt );
        } );
    </script>
} ?>
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.

本文标签: jqueryAdd quotonclickquot option to header menu item