Tagged: search form
Hi.
My site is a member-only site. However, when I put the search form beside the menu bar, the problem was that users who did not log in would be able to use the search function.
I wonder if I can make the search icon visible only to login users.
If that is not possible, I’d like to be able to add the search icon to the top of every page, not the menu bar.
Can I get help?
well there is an if clause that could fit for your needs:
if(is_user_logged_in())
but the most elegant method would be to influence the header_searchicon from Enfold Options dialog.
This here only hides or shows the search – but better would be that there is no search in the menu
(comes to functions.php of your child theme)
function login_state(){
if(is_user_logged_in()){
?>
<script>
jQuery("#menu-item-search").css("display", "block");
</script>
<?php
}
else{
?>
<script>
jQuery("#menu-item-search").css("display", "none");
</script>
<?php
}
}
add_action('wp_footer', 'login_state');
maybe a filter like avf_header_setting_filter could do the needed trick – but i do not see how to ( on that early time )
Aha here is the solution – and it comes to functions.php of your child-theme
thanks to Dude
add_action('init', 'avia_remove_search_for_logged_out_users', 10);
function avia_remove_search_for_logged_out_users(){
if(! is_user_logged_in()){
remove_filter( 'wp_nav_menu_items', 'avia_append_search_nav', 9997, 2 );
remove_filter( 'avf_fallback_menu_items', 'avia_append_search_nav', 9997, 2 );
}
}
Hi, Guenni007
Thank you for your kind reply. I will try it. And I will give you feedback again.
Wow! It’s very simple, and works well.
Thank you very much.
Not for that – your welcome
Hi,
Thanks for helping out @guenni007, much appreciated. Please let us know if you should need any further help on the topic or if we can close it @leekiya.
Best regards,
Rikard