Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1052574

    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?

    #1052629

    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 )

    #1052641

    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 );
    	}
    }
    #1052824

    Hi, Guenni007
    Thank you for your kind reply. I will try it. And I will give you feedback again.

    #1052829

    Wow! It’s very simple, and works well.
    Thank you very much.

    #1052863

    Not for that – your welcome

    #1052989

    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

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.