• Resolved KTS915

    (@kts915)


    You are certainly very brave to have taken the step of rewriting from scratch a very popular plugin! I hope you still feel that all the effort was worthwhile!

    My question is this. While I know I could use display: none; in CSS, I would much prefer not to have the menu be output at all for logged-out visitors. With the previous version, I used the following code to hide the menu from logged-out visitors:

    if ( !is_user_logged_in() ) {
         remove_action( 'wp_footer', array( 'RM_HTMLController', 'display' ) );
    }

    The new code looks substantially more complex, so I haven’t been able to work out something equivalent. What do you suggest?

    https://wordpress.org/plugins/responsive-menu/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor responsivemenu

    (@responsivemenu)

    Hey KTS,

    It sure was a nervous step and I spent the last 3 months non-stop doing it, lets hope its worth it in the long run!!

    My way of dealing with this situation is to use the shortcode in my pages like the examples in the page below:

    https://responsive.menu/faq/how-do-i-show-different-menus-on-different-pages/

    Of course you can replace the if function with the one for logged in users.

    Does that help at all?

    Thread Starter KTS915

    (@kts915)

    I’ll be honest: I don’t really like that way of accomplishing a task because (a) the only efficient way to do this in my case is by editing the header.php template, whereas I’d prefer to put it with other functions in the functions.php file, and (b) it always seems wrong to me to put a shortcode in a template file.

    Nevertheless, it does work, so thank you.

    I just added a conditional to make it fail gracefully if the plugin isn’t activated. So, in case it’s of use to anyone else, I am now using this:

    <?php
    if( function_exists ( 'activate_responsive_menu' ) && is_user_logged_in() )  {
    	echo do_shortcode('[responsive_menu]');
    } ?>

    Plugin Contributor responsivemenu

    (@responsivemenu)

    Hey KTS,

    In that case can’t you do something like this in your functions.php file?

    if(is_user_logged_in())  {
       add_action('wp_footer', function() {
         echo do_shortcode('[responsive_menu]');
       },1000);
    }

    I just tested it on my dev site and it seems to work well.

    All the best

    Thread Starter KTS915

    (@kts915)

    Ah, yes, that’s the way to do it!

    I had tried before to hook a function onto add_action('wp_footer', ... but I never thought to try echoing the shortcode!

    Thanks very much indeed!

    Plugin Contributor responsivemenu

    (@responsivemenu)

    Hey KTS,

    You’re welcome! Its not something I have ever done but in theory it should work and turns out that it does!

    Great news!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to prevent menu showing when user not logged in?’ is closed to new replies.