I am trying to remove a button for all logged in users on my website. When logged out I have a register button on the start page - which I want to remove when a user log in. Not a menu item - a button on the start page.
I have tried this code in the child theme function file:
function example_function()
{
if ( is_user_logged_in() )
{
.hide-me {
display: none;
}
}
add_action('init', 'example_function');
}
However this gives my site critical error.
.hide-me is a css class I use on the button when I edit in elementor page builder.
Not sure what I do wrong. Do you know and can you please help me?
The general idea is good but You are mixing php and css. Also, since you are echo-ing some styles on the page, it's better to use wp_head
hook. This assumes that the button has a css class called hide-me
.
function example_function() {
if (is_user_logged_in()) {
echo '<style>.hide-me { display: none; }</style>';
}
}
add_action('wp_head', 'example_function');