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
1 Answer
Reset to default 0I 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
版权声明:本文标题:jquery - Add "onclick" option to header menu item 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744802906a2625972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论