Archived topic
Is there a way to make the Off Canvas Panel only appear for logged Users?
19 replies · Started by Jonathon on September 9, 2021
That is cool. Where would you suggest I add this? It doesn't look like something you would put in a functions.php file.
Hi,
The PHP you can put in the functions.php of your child theme or in a code snippet. You can place the CSS inside your child theme's style.css or inside the Additional CSS section inside the Customizer.
Okay, final question for clarity. In this line.
if ( in_array( '<rolename>', (array) $user-roles ) ) {
If I wanted this to work with more than one role I could put the role names with , between them correct?
So '<rolename1>,<rolename2>,' would work?
No, that function only accepts one role to check against the user. If you only have a few roles you could use the code below instead.
<?php
$user = wp_get_current_user();
if ( in_array( '<rolename>', (array) $user-roles ) || in_array( '<rolename>', (array) $user-roles ) ) {
wp_add_inline_style( '<cssname>', '.main-navigation .menu-bar-item.slideout-toggle{display:block;}' );
}
Just copy the in_array( '<rolename>', (array) $user-roles ) inside the if statement separated by ||.
So the if statement becomes: if this or that do this.
None of this seems to work in Code Snippet. This is all of the error provided.
The code snippet you are trying to save produced a fatal error on line 2:
Uncaught Error: Unsupported operand types in /var/web/site/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(221) : eval()'d code:2 Stack trace: #0 /var/web/site/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(221): eval() #1 /var/web/site/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(271): Code_Snippets_Edit_Menu->test_code(Object(Code_Snippet)) #2 /var/web/site/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(130): Code_Snippets_Edit_Menu->save_posted_snippet() #3 /var/web/site/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(107): Code_Snippets_Edit_Menu->process_actions() #4 /var/web/site/public_html/wp-includes/class-wp-hook.php(303): Code_Snippets_Edit_Menu->load('') #5 /var/web/site/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array) #6 /var/web/site/public_html/wp-includes/plugin.php(470): WP_Hook->do_action(Arr
I'm assuming I am doing something wrong with the entry here is what I tried:
<?php
$user = wp_get_current_user();
if ( in_array( 'accreditation_team_one', (array) $user-roles ) || in_array( 'accreditation_team_two', (array) $user-roles ) )
{
wp_add_inline_style( 'approved-accreditation-team-css', '.main-navigation .menu-bar-item.slideout-toggle{display:block;}' );
}
This seemed so easy in my head.