Remove Forum Menu from Logged Out View Only?
Quote from timmy321 on August 22, 2020, 12:53 amHi,
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
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
Quote from Quenso on August 23, 2020, 4:50 amHello @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!
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!
Quote from timmy321 on August 23, 2020, 1:12 pmHi 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
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
Quote from Quenso on August 24, 2020, 6:43 amYou 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.
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.
Quote from timmy321 on August 24, 2020, 1:39 pmAh I see!
Perhaps with more experience I may feel that way too, however for now I’m just happy it works! 🙂
Take care,
Timmy
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
Quote from qualmy91 on August 25, 2020, 3:25 amHello 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.
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.
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.
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.
Quote from Quenso on August 25, 2020, 4:09 am@qualmy91
I’m not using this function anymore.
Sure, i did not forgot about it.
I’m not using this function anymore.
Sure, i did not forgot about it.
Quote from timmy321 on August 25, 2020, 10:39 pmOk 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>’;
}
});
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>’;
}
});
Quote from qualmy91 on August 26, 2020, 4:05 amHey @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(); }
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();
}
