Please or Register to create posts and topics.

Remove Forum Menu from Logged Out View Only?

Page 1 of 2Next

Hi,

 

Now that the Login & Register words in the notification banner are hyperlinked, I wondered if anyone knew how to remove the Forum Menu for logged out users, but have it remain for Logged In users?

 

I’ve searched the forum’s & haven’t found a way round this yet. I’ve tried hiding it with CSS, however this hides it for both logged out & logged in views.

 

Any help would be greatly appreciated.

 

Kind regards,

 

Tim

 

Hello @timmy321

This is the way i made it happen in one of my plugins:

Add to themes functions.php:

add_action('asgarosforum_content_top', function() {
  if (!is_user_logged_in()) {
    echo '<div id="hide-forum-menu">';
  }
});
add_action('asgarosforum_content_header', function() {
  if (!is_user_logged_in()) {
    echo '</div>';
  }
});

Add CSS:

#hide-forum-menu {
  display: none !important;
}

It’s not the best solution. If you find a way thats working better let me know!

qualmy91 and timmy321 have reacted to this post.
qualmy91timmy321

Hi Quenso,

 

That’s incredibly helpful of you, thank you! It worked a treat 🙂

I’ve been flat out problem solving all weekend so far with other website things, so it’s very nice to have something work first time! 🙂

 

How come it’s not the best solution?

 

Kind regards,

 

Timmy

You are welcome.

It’s not the best solution for me because I don’t like to add code via 2 different actions. The easier and better way is to tell the menu not to show up in the code directly without extra div’s and CSS.

timmy321 has reacted to this post.
timmy321

Ah I see!

 

Perhaps with more experience I may feel that way too, however for now I’m just happy it works! 🙂

 

Take care,

 

Timmy

Hello together,

if you want to use this code you should add the following lines:

add_action('asgarosforum_post_custom_content_top', function() {
  if (!is_user_logged_in()) {
    echo '</div>';
  }
});

The hook “asgarosforum_content_header” is not called for the post view. So it could break the page if you use the single post shortcode.

@timmy321

If you are not planning to use this shortcode you don’t have to add this line. But I would still recommend to add it since you never know what you will do in the future. Than it would be difficult to find find the reason for the error.

@quenso

Please keep in mind that you can always ask for some additional hooks or suggest some changes that you need for your plugin.

I will create a filter for the header and maybe add a class to the body tag for logged in/out users.

Need professional help with Asgaros Forum? Book an appointment with us at domra Web Solutions for setup and customization services. Learn more about our Toolbox for Asgaros Forum plugin to enhance your forum experience.

@qualmy91

I’m not using this function anymore.

Sure, i did not forgot about it.

 

qualmy91 has reacted to this post.
qualmy91

Ok thank you for adding that @qualmy91

 

Just to confirm, you recommend adding that line beneath the code that Quenso recommended – not instead of?

 

So the final code would look like this?

 

add_action(‘asgarosforum_content_top’, function() {
if (!is_user_logged_in()) {
echo ‘<div id=”hide-forum-menu”>’;
}
});
add_action(‘asgarosforum_content_header’, function() {
if (!is_user_logged_in()) {
echo ‘</div>’;
}
});

add_action(‘asgarosforum_post_custom_content_top’, function() {
if (!is_user_logged_in()) {
echo ‘</div>’;
}
});

 

Hey @timmy321,

yes you should add this line to prevent breaking the page.

I also created a filter to hide the header on GitHub. You can check the status there and when it’s approved by @asgaros it will be part of the next update of Asgaros Forum.

The code would be really simple than:

// Add filter to hide forum header for logged out users
add_filter ( 'asgarosforum_filter_show_header', 'hide_header');

// Function to hide header
function hide_header(){
    return is_user_logged_in();
}

 

Asgaros and timmy321 have reacted to this post.
Asgarostimmy321
Need professional help with Asgaros Forum? Book an appointment with us at domra Web Solutions for setup and customization services. Learn more about our Toolbox for Asgaros Forum plugin to enhance your forum experience.

I see, excellent stuff! Thanks @qualmy91

 

 

qualmy91 has reacted to this post.
qualmy91
Page 1 of 2Next